MongoDB: How to concatenate document ids to a unique string -


given collections this...

{ "_id" : objectid("5546371e470000570184a633"), "name" : "john", "age": 31 } { "_id" : objectid("5546381e470000570184a634"), "name" : "mike", "age": 35 } { "_id" : objectid("5546391e470000570184a635"), "name" : "jack", "age": 28 } 

... how merge _id of guys older 30? result i'm looking is

{ "_ids" : "5546371e470000570184a633,5546381e470000570184a634,5546391e470000570184a635" } 

i used find , iterate on result concatenate _ids... perhaps more convenient way.

i not see problem approach. here different one:

db.coll.distinct("_id", {age: {$gt: 30}}).map(function(el){   return el.str; }).join(",") 

i realize _id distinct definition.


Comments