mongodb - How to retrieve array value index wise -
how retrieve array value index-wise in mongodb? in below query, want computers
answer:
> db.customers.find({}, { likes : { $slice: 1}}).pretty() { "_id" : objectid("57709662a93160be074de74a"), "name" : "john", "age" : "40", "likes" : [ "computers" ] }
is looking for
db.customers.aggregate([{$project:{_id:0,selected:{$slice:["$likes", 1]}}},{$unwind:"$selected"}]);
Comments
Post a Comment