brent
brent

Reputation: 924

$not operator in mongodb not working

Im currently writing a nodejs web app that uses mongodb for all the database work. Im currently trying to run a query to remove all documents that match one criteria and not match another.

Here is the code:

{ $and:[ {name:"bob"}, { hair: { $not: "brown" } } ] }

However it returns

MongoError: invalid use of $not

Thanks for the help

Upvotes: 2

Views: 618

Answers (1)

Thilo
Thilo

Reputation: 262714

You want $ne instead:

{ hair: { $ne: "brown" } }

$not is used for logical disjunctions, not for field comparisons.

Upvotes: 3

Related Questions