Skip to content

Instantly share code, notes, and snippets.

@alg
Created August 25, 2011 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alg/1170282 to your computer and use it in GitHub Desktop.
Save alg/1170282 to your computer and use it in GitHub Desktop.
MongoDB id/array queries
> db.m.insert({ body: '1', phone_id: 1 })
> db.m.insert({ body: '2', phone_id: [ 1, 2 ]})
> db.m.find({ phone_id: 1 })
{ "_id" : ObjectId("4e56089fbdfcdc0f68c894ae"), "body" : "1", "phone_id" : 1 }
{ "_id" : ObjectId("4e5608afbdfcdc0f68c894af"), "body" : "2", "phone_id" : [ 1, 2 ] }
> db.m.find({ phone_id: 2 })
{ "_id" : ObjectId("4e5608afbdfcdc0f68c894af"), "body" : "2", "phone_id" : [ 1, 2 ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment