Database Reference
In-Depth Information
A MongoDB Metric Collection
Creating a simple metric collection in MongoDB is easy using the
upsert feature of the update command. To begin, create a metric
collection and define an index with a time-to-live to allow the data to
expire after seven days:
> db.createCollection("metrics");
{ "ok" : 1 }
>
db.metrics.ensureIndex({ts:1},{expireAfterSeconds:86400*7});
> db.metrics.getIndexes();
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "mine.metrics",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"ts" : 1
},
"ns" : "mine.metrics",
"name" : "ts_1",
"expireAfterSeconds" : 604800
}
]
The ideal situation would be to use the _id field as a date; each one will
be unique, but this unfortunately does not work. Instead the timestamp
to be aggregated must be kept in two keys. In the long run, this is
probably desirable because metrics may be broken down to something
 
Search WWH ::




Custom Search