Skip to content

Instantly share code, notes, and snippets.

@crystalneth
Created April 17, 2012 00:56
Show Gist options
  • Save crystalneth/2402651 to your computer and use it in GitHub Desktop.
Save crystalneth/2402651 to your computer and use it in GitHub Desktop.
// Can't get $and working
// This is Mongo 2.0.4
```
> db.foo.insert({letter: 'a', number: 2})
> db.foo.find()
{ "_id" : ObjectId("4f8cbf5b19a4296c4255028e"), "letter" : "a", "number" : 2 }
> db.foo.find({letter: 'a'})
{ "_id" : ObjectId("4f8cbf5b19a4296c4255028e"), "letter" : "a", "number" : 2 }
> db.foo.find({letter: 'a', number: 2})
{ "_id" : ObjectId("4f8cbf5b19a4296c4255028e"), "letter" : "a", "number" : 2 }
// WHY DON"T ANY OF THESE RETURN RECORDS?
> db.foo.find({$and: [{letter: 'a', number: 2}]})
> db.foo.find({$and: [{letter: 'a'}, {number: 2}]})
> db.foo.find({$and: [{letter: 'a'}]})
> db.foo.find({$and: []})
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment