{
metadata: {
topic: "memory_used:,
group: "group1"
ts_day: ISODate("2013-10-10T00:00:00.000Z"),
}
values: {
0: { 0: 999999, 5: 999999, …, 55: 1000000 },
1: { 0: 999999, 5: 999999, …, 55: 1000000 },
2: { 0: 999999, 5: 999999, …, 55: 1000000 },
}
}I’m not opposed to changing the data around to fit a better model.
I’ll admit i’m new to mongo and not positive i’m doing it right…
Hi Michael,
Data in MongoDB has a flexible schema, and this means your data model can be designed to benefit how the applications will use the data.
Depending on your applications use case, there are a number of possible data schemas you can try. One example, you could modify the hour to contain an array of minutes.
values:{
0: [9999, 9999, 9999, 9999],
1: [9999, 9999, 9999, 9999],
2: [9999, 9999, 9999, 9999]
...
};
/* Fetch aggregation of hour 0 */
db.collection.aggregate([
{$unwind:"$values.0"},
{$group:
{_id: "$metadata.group",
hour0: {$sum: "$values.0" }
}
}
]);
See Data Modelling Introduction for more examples.
If you would like to stay with your current schema, you can try this aggregation script:
/* Match the document that you wanted */
var match = {
"metadata.topic": "memory_used",
"metadata.ts_day": ISODate("2013-10-10T00:00:00.000Z")
};
/* Assuming that group is unique per day */
var project = {"_id":"$metadata.group"};
for (var hour=0; hour<24; hour++){
/* Add values with incremental of 5 minutes */
var minutes = [];
for (var min=0; min<60; min=min+5){
minutes.push("$values."+hour+"."+min);
}
project["hour"+hour] = {"$add": minutes};
};
printjson(
db.collection.aggregate([
{$match: match},
{$project: project}
]).toArray()
);
The example above utilises $add to add all the values for the hour.
Kind regards,
Wan.
I guess i'll have to brush up on my javascript then. The data model i
used was from the time-series mongo example i (and everyone else)
seems to reference on the web. but there isn't much, clearly written,
around on how to exact useful information from it.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CABOsP2MAe7Gu6Uzk7so4Egqu0zrPoGRQkBuWj%3DwfUytMYAv0Hw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.