MANU
unread,May 25, 2012, 8:49:01 AM5/25/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
Hi everybody,
I developped a map/reduce with the aggregation framework of mongo.
Here is my data :
db.coll.save({a:'Martin',b:'wesh',c:5})
db.coll.save({a:'Martin',b:'wesh',c:15})
db.coll.save({a:'Martin',b:'wesh',c:2})
db.coll.save({a:'Manu',b:'bri',c:1})
db.coll.save({a:'Manu',b:'bri',c:2})
db.coll.save({a:'Manu',b:'bri',c:10})
db.coll.save({a:'Manu',b:'bri',c:6})
The result I want :
martin wesh : 2
Manu bri : 1
Here is my code :
db.coll.group(
{key: { a:true, b:true },
reduce: function(obj,prev) { if (prev.min > obj.c)
{prev.min = obj.c}; },
initial: { min: 15 }
});
I want to replace : " initial: { min: 15 } " BY " initial: { min:
db.coll.find({},{c:1}).sort({c:-1}).limit(1) } "
but the last way return {"_id" : 5654653 , "c" : 15} and not only 15
What's the solution guys ?
Thanks a lot.
Best regards