This question already has answers here:
mongodb $not _id
(2个答案)
3年前关闭。
这是我的查找请求:
这里是文档:https://docs.mongodb.com/manual/reference/operator/query/not/index.html
这是错误:
我想查找当前用户未编写的所有食谱。参数工作正常,所以这不是问题。一定有办法做到这一点,否则我做错了吗?
(2个答案)
3年前关闭。
这是我的查找请求:
Recipe.find({'author.id': {$not: {user}}}
这里是文档:https://docs.mongodb.com/manual/reference/operator/query/not/index.html
这是错误:
Error: Can't use $not with ObjectId.
我想查找当前用户未编写的所有食谱。参数工作正常,所以这不是问题。一定有办法做到这一点,否则我做错了吗?
最佳答案
您应该使用 $ne
Recipe.find({ "author.id": { "$ne": user }});
关于javascript - Mongoose find()无法与$ not查询一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47297976/
10-10 12:27