Skip to content

Instantly share code, notes, and snippets.

@scotthernandez
Created August 9, 2010 16:04
Show Gist options
  • Save scotthernandez/515635 to your computer and use it in GitHub Desktop.
Save scotthernandez/515635 to your computer and use it in GitHub Desktop.
> db.test7.insert({firstName: 'testme',lastName: 'testme', devices: [{address: 'testme@not.a.domain', type: 'EMAIL'}]})
> db.test7.ensureIndex({'devices.address': 1, 'devices.type': 1})
> db.test7.find({devices: { $elemMatch: {address: /^testme/, type: 'EMAIL'}}}).explain()
{
"cursor" : "BtreeCursor devices.address_1_devices.type_1 multi",
"nscanned" : 1,
"nscannedObjects" : 1,
"n" : 1,
"millis" : 1,
"indexBounds" : {
"devices.address" : [
[
"testme",
"testmf"
],
[
/^testme/,
/^testme/
]
],
"devices.type" : [
[
"EMAIL",
"EMAIL"
]
]
}
}
> db.test7.find({devices: { $elemMatch: {address: {$regex:"^testme"}, type: 'EMAIL'}}}).explain()
{
"cursor" : "BasicCursor",
"nscanned" : 1,
"nscannedObjects" : 1,
"n" : 1,
"millis" : 0,
"indexBounds" : {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment