Also, if someone asks how to cancel the elemental search, that is, find a record that matches both βredβ and βblueβ, and does NOT match βgreenβ and βwhiteβ, this can be achieved with using $ nin , which may be unclear when someone reads $ nin docs ( http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24nin - the description of the parsing was difficult for me):
db.my_collection.find({tags: { $all : ["red","blue"], $nin : ["green", "white" ]}})
This is very cool because it allows a relatively good negation search syntax:
tokenRequired1 tokenRequired2 !tokenForbidden1 !tokenForbidden2
A very natural Gmail style search.
As suggested here and here, you could do a full text search if you create an array of all tokens from a record, although I have no idea if it is effective or even the best way to do this.
source share