Skip to content

Instantly share code, notes, and snippets.

@mehdimehdi
Created May 15, 2011 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehdimehdi/973354 to your computer and use it in GitHub Desktop.
Save mehdimehdi/973354 to your computer and use it in GitHub Desktop.
Mongo db results command
> db.activity.find({'publisher_id':746,'user_id':2425,'points':{'$ne':0}},{'user_id':1,'points':1,'date_created':1})
{ "_id" : ObjectId("4dcd50e50db4495925000681"), "user_id" : 2425, "points" : 100, "date_created" : "Fri May 13 2011 08:40:21 GMT-0700 (PDT)" }
{ "_id" : ObjectId("4dcd50e50db4495925000682"), "user_id" : 2425, "points" : 100, "date_created" : "Fri May 13 2011 08:40:21 GMT-0700 (PDT)" }
{ "_id" : ObjectId("4dcd523f0db4495925000697"), "user_id" : 2425, "points" : 100, "date_created" : "Fri May 13 2011 08:46:07 GMT-0700 (PDT)" }
{ "_id" : ObjectId("4dce3f190db4495ba30000a0"), "user_id" : 2425, "points" : 100, "date_created" : "Sat May 14 2011 01:36:41 GMT-0700 (PDT)" }
{ "_id" : ObjectId("4dcee2fc0db4495ba30007ac"), "user_id" : 2425, "points" : 100, "date_created" : "Sat May 14 2011 13:15:56 GMT-0700 (PDT)" }
> db.activity.group({key:{'user_id':true},cond:{'publisher_id': 746},reduce:function(doc, prev) {prev.points+=doc.points;},initial:{'points': 0}})
[
{
"user_id" : 3,
"points" : 200
},
{
"user_id" : 4,
"points" : 100
},
{
"user_id" : 5,
"points" : 100
},
{
"user_id" : 116,
"points" : 200
},
{
"user_id" : 2425,
"points" : 3700
},
{
"user_id" : 2508,
"points" : 800
},
{
"user_id" : 2519,
"points" : 600
},
{
"user_id" : 2804,
"points" : 300
},
{
"user_id" : 2929,
"points" : 300
},
{
"user_id" : 26,
"points" : 100
},
{
"user_id" : 3452,
"points" : 500
},
{
"user_id" : 3582,
"points" : 400
},
{
"user_id" : 3588,
"points" : 300
},
{
"user_id" : 3847,
"points" : 1500
},
{
"user_id" : 4027,
"points" : 1000
},
{
"user_id" : 55,
"points" : 100
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment