Matched elements from mongodb records -


suppose have following documents in collection

{      "_id":objectid("562e7c594c12942f08fe4192"),    "tags" : [          {             "tagname" : "fun",             "created" : isodate("2016-01-22t06:13:56.510z")         },          {             "tagname" : "cool",             "created" : isodate("2016-01-22t06:13:56.509z")         },          {             "tagname" : "good",             "created" : isodate("2016-01-22t06:13:56.509z")         }     ] }, {      "_id":objectid("562e7c594c12942f08fe4193"),    "tags" : [          {             "tagname" : "super",             "created" : isodate("2016-01-22t06:13:56.509z")         },          {             "tagname" : "fun",             "created" : isodate("2016-01-22t06:13:56.509z")         }     ] } 

i want search relative tags , want display tag array only.

how can query list of tag names?

to query specific field in mongodb can use find method projection parameter: https://docs.mongodb.org/manual/reference/method/db.collection.find/

db.test.find({}, {"tags.tagname":1,"_id":0}).pretty() {     "tags" : [         {             "tagname" : "fun"         },         {             "tagname" : "cool"         },         {             "tagname" : "good"         }     ] } 

the first parameter blank {} because don't have query , second parameter projection. embedded document have use dot notation "tags.tagname". "_id":0 not display _id field.


Comments