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
Post a Comment