Skip to content

Instantly share code, notes, and snippets.

@cheald
Created August 21, 2013 08:38
Show Gist options
  • Save cheald/6291848 to your computer and use it in GitHub Desktop.
Save cheald/6291848 to your computer and use it in GitHub Desktop.
PRIMARY> db.rows.insert({posts: [{title: 'foo'}, {title: 'bar'}]})
PRIMARY> db.rows.insert({posts: [{title: 'baz'}, {title: 'bin'}]})
PRIMARY> db.rows.find({posts: {$elemMatch: {title: "foo"}}})
{ "_id" : ObjectId("52147be905abf6eada01c845"), "posts" : [ { "title" : "foo" }, { "title" : "bar" } ] }
PRIMARY> db.rows.find({posts: {$elemMatch: {title: "bin"}}})
{ "_id" : ObjectId("52147bef05abf6eada01c846"), "posts" : [ { "title" : "baz" }, { "title" : "bin" } ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment