--
You received this message because you are subscribed to the Google Groups "node-mongodb-native" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-mongodb-na...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to node-mongodb-native+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to node-mongodb-na...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to node-mongodb-native+unsubscribe...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to node-mongodb-native+unsubscribe...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to node-mongodb-na...@googlegroups.com.
I found a way to do what I wanted to do. This seems kind of klugey to me, so if anyone can find a better way, please let me know. My solution uses the underscore.js library (also posted this on SO):
var _ = require('underscore');
vary query = {}
query['foo'] = 'bar'
Db.connect(mongoUri, function (err, db) {
if (!err) {
db.collection(analyticsCollection, function (err, coll) {
if (!err) {
coll.save(_.extend(query,{"datetime":new Date()}), {safe:true}, function (err, result) {
db.close();
res.send(200,result);
//console.log(result);
});
} else {
res.json(503,{errno:503,msg:'error: collection does not exist.'});
}
});
} else {
res.json(503,{errno:503,msg:'error: database does not exist.'});
}
});Now I can do the aggregation (without needing to use the $project operator):
> db.analytics.aggregate([{$group:{_id:{day:{$dayOfMonth:"$datetime"}}}}])
{ "result" : [ { "_id" : { "day" : 15 } } ], "ok" : 1 }Hope this helps someone.