7

I have a collection with records like this:

{
    "_id" : ObjectId("50ae3bdb50b3d6f01400027a"),
    "admins": 
       [ObjectId("50ae3bdb50b3d6f014000279"), ObjectId("50ae3bdb50b3d6f01400027e")]
}

I would like to search by the the 'admin' array.

How can I find all documents included for example ObjectId("50ae3bdb50b3d6f014000279") in the sub-array.

Thank you.

Tomas Randus
  • 2,127
  • 4
  • 29
  • 38
  • Why did you delete [this](http://stackoverflow.com/questions/14941011/non-valid-json-with-escaped-commas-in-javascript)? The Solution is `JSON.parse( '{ "title_text": "\\\"s\\\"" }' )` – Šime Vidas Feb 18 '13 at 16:44

1 Answers1

12

You can match against array fields like admins the same as you would a non-array field:

db.coll.find({admins: ObjectId("50ae3bdb50b3d6f014000279")})
JohnnyHK
  • 305,182
  • 66
  • 621
  • 471