How can I perform a search in mongoose where a field (which is an array) contains something?
You want $all
.
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24all
Here are a couple of examples from mongoose:https://github.com/LearnBoost/mongoose/blob/master/test/query.test.js#L396
On a side note, $where
is typically not scalable.
MongoDB query syntax allows you to match an element array like that:
.find( { tags: 'tag1' } )
And, of course, it's working with Mongoose :)
Source: http://docs.mongodb.org/manual/tutorial/query-documents/#match-an-array-element