Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoose find() not working with $not query [duplicate]

Here is my find request:

Recipe.find({'author.id': {$not: {user}}}

Here is the documentation: https://docs.mongodb.com/manual/reference/operator/query/not/index.html

Here is the error:

Error: Can't use $not with ObjectId.

I want to find all Recipes that are not authored by the current user. The arguments are working fine, so that's not the issue. There must be a way to do this, or am I doing something wrong?

like image 251
David Avatar asked Dec 11 '25 04:12

David


1 Answers

You should use $ne

Recipe.find({ "author.id": { "$ne": user }});
like image 71
Sajeetharan Avatar answered Dec 13 '25 18:12

Sajeetharan