Skip to content

Instantly share code, notes, and snippets.

@clizzin
Created January 29, 2011 04:06
Show Gist options
  • Save clizzin/801515 to your computer and use it in GitHub Desktop.
Save clizzin/801515 to your computer and use it in GitHub Desktop.
> db.foo.insert({a: {john: true, george: true}})
> db.foo.insert({a: {paul: true, ringo: true}})
> db.foo.find()
{ "_id" : ObjectId("4d43912ceb913a1024b1410f"), "a" : { "john" : true, "george" : true } }
{ "_id" : ObjectId("4d43914beb913a1024b14110"), "a" : { "paul" : true, "ringo" : true } }
> db.foo.find({'a.john': {$exists: true}})
{ "_id" : ObjectId("4d43912ceb913a1024b1410f"), "a" : { "john" : true, "george" : true } }
> db.foo.find({'a.paul': {$exists: true}})
{ "_id" : ObjectId("4d43914beb913a1024b14110"), "a" : { "paul" : true, "ringo" : true } }
> db.foo.find({$or: [{'a.john': {$exists: true}}, {'a.paul': {$exists: true}}]})
>
> db.foo.stats()
{
"ns" : "topher_test.foo",
"count" : 2,
"size" : 96,
"storageSize" : 2816,
"numExtents" : 1,
"nindexes" : 1,
"lastExtentSize" : 2816,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 8192,
"indexSizes" : {
"_id_" : 8192
},
"ok" : 1
}
@scotthernandez
Copy link

db.foo.find({$or: [{'a.john': {$exists: true}}, {'a.paul': {$exists: true}}]})
{ "_id" : ObjectId("4d4392e753ffe3441923319b"), "a" : { "john" : true, "george" : true } }
{ "_id" : ObjectId("4d4392f053ffe3441923319c"), "a" : { "paul" : true, "ringo" : true } }

@clizzin
Copy link
Author

clizzin commented Jan 31, 2011

Turns out the issue with $or not working is that I was using an old version released prior to the introduction of $or.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment