Finding all records containing a given subfield in mongodb

Viewed 8676

In mongodb, i can find all those records in a collection in database db that contain a particular field using the following query

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

Now consider the following document:

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

              }
}

What would be the query for getting all records having the id field in metadata ?

Please Help. Thank You

1 Answers
Related