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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -