Finding all records containing a given subfield in mongodb -


in mongodb, can find records in collection in database db contain particular field using following query

var doc = db.collection_name.find({field_name:{$exists:true}}) 

now consider following document:

{   "somefield":"someval",   "metadata": {"id":"someval",                "client_url":"http://www.something.com"                } } 

what query getting records having id field in metadata ?

please help. thank you

you can use dot notation reference sub-document fields

var doc = db.collection_name.find({"metadata.id":{$exists:true}}) 

Comments

Popular posts from this blog

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -