Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
mongoose-timeseries
Advanced tools
a time series data and analytics storage plugin for Mongoose.
npm install mongoose-timeseries
var YourDocumentSchema = new Schema({
attr1: { type: Schema.Types.ObjectId, ref: 'attr1' },
attr2: { type: Schema.Types.ObjectId, ref: 'attr2' },
date: { type: Date, default: Date.now },
analytics: {
metric: { type: Number }
},
info: {
sub1: { type: String },
sub2: { type: String },
sub3: { type: String }
}
})
var mongoose = require('mongoose')
var timeseries = require('mongoose-timeseries')
YourDocumentSchema.plugin(timeseries, {
name: 'TimeSeriesDocument',
dateKey: 'date',
intervals: ['minute', 'day'],
keys: [
{
key: 'attr1'
},
{
key: 'attr2'
},
{
key: 'info',
value: function(doc) {
return doc.sub1 + doc.sub2 + doc.sub3
}
}
],
sums: [
{
name: 'metric',
key: 'analytics.metric'
}
]
})
Saved time series documents will look like:
{
interval: 'day',
timestamp: Mon Aug 01 2016 00:00:00 GMT-0600(MDT),
created: Mon Aug 01 2016 00:51:09 GMT-0600(MDT),
updated: Wed Aug 31 2016 22:19:42 GMT-0600(MDT),
data: {
count: 5,
metric: {
sum: 697,
count: 5
}
},
key: {
attr1: 55931aba4f3b26d63810a55d,
attr2: 5536011b00a57af8243d7e5b,
info: 'ABC'
},
_id: 57 a50178e47cea6f5d7f1c3b
}
YourDocumentSchema.plugin(timeseries, options(Object))
You can apply multiple times with different options:
YourDocumentSchema.plugin(timeseries, options1(Object))
YourDocumentSchema.plugin(timeseries, options2(Object))
YourDocumentSchema.plugin(timeseries, options3(Object))
name(String)
The collection name of the specific time series data.
dateKey(String)
The custom date key of your schema (if applicable).
If not set, defaults to document._id.getTimeStamp()
intervals(Array)
The time series intervals you want: Can include any or all of ['minute', 'hour', 'day', 'month']
keys(Array)
The unique information you'd like your time series to separate and store.
keys.key(String)
The name of the key.
keys.value(Function)
The function that returns your a value to store on the associated key: Defaults to the name of the key
sums(Array)
The sums you'd like to keep track of.
sum.name(String)
The name of the sum.
sum.key(String)
The key of the sum. Can be nested like:
'analytics.metrics.metric1'
Now, in your front-end analytics, you can query the time series data like:
var startDateFromUI = ...
var endDateFromUI = ...
TimeSeriesAnalyticsModel.find({
interval: 'day',
timestamp: {
$gte: startDateFromUI,
$lte: endDateFromUI
}
} function(err, results) {
addAverage(results, 'metric')
var avg = totalAverage(results, 'metric')
})
And once you collect that data you can perform calculations however you please.
For example, calculate the average:
function addAverage(results, metric) {
for (var i = 0; i < results.length, i++) {
var result = results[i]
result.data[metric].average = result.data[metric].sum / result.data[metric].count
}
}
function totalAverage(results, metric) {
var totalSum, totalCount = 0
for (var i = 0; i < results.length; i++) {
totalSum += results.data[metric].sum
totalCount += results.data[metric].count
}
return totalSum / totalCount
}
npm install
npm test
FAQs
a time series data and analytics storage plugin for Mongoose
The npm package mongoose-timeseries receives a total of 3 weekly downloads. As such, mongoose-timeseries popularity was classified as not popular.
We found that mongoose-timeseries demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.