Skip to content

Instantly share code, notes, and snippets.

@jakul
Last active August 29, 2015 13:58
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 jakul/10285179 to your computer and use it in GitHub Desktop.
Save jakul/10285179 to your computer and use it in GitHub Desktop.
> db.xxx.insert({'colours':['red']})
> db.xxx.insert({'colours':['red']})
> db.xxx.insert({'colours':['blue']})
> db.xxx.insert({'colours':['blue', 'red']})
> db.xxx.insert({'colours':['green']})
> db.xxx.find({ $or: [{"colours": {$in: ['red']}}}] }).count()
Wed Apr 9 15:47:41.383 SyntaxError: Unexpected token }
> db.xxx.find({ $or: [{"colours": {$in: ['red']}}] }).count()
3
> db.xxx.find({ $or: [{"colours": {$in: ['blue']}}] }).count()
2
# This finds "document with any matching colour"
> db.xxx.find({ $or: [{"colours": {$in: ['blue']}}, {"colours": {$in: ['red']}}] }).count()
4
# This finds "document which matches all colours"
> db.xxx.find({ $and: [{"colours": {$in: ['blue']}}, {"colours": {$in: ['red']}}] }).count()
1
> db.xxx.find({ $and: [{"colours": {$in: ['blue']}}, {"colours": {$in: ['red']}}, {"colours": {$in: ['purple']}}] }).count()
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment