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

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -