我想通过Schema.find()
获取多个文档,但是排除一个特定的文档(通过其id)。目前,我的查询如下:
Product
.find({
$or: [
{ 'tags': { $regex: criteria, $options: 'i' }, },
{ 'name': { $regex: criteria, $options: 'i' }, },
],
})
.limit(10)
.exec((err, similar) => {
//...
})
我试图在查询中添加$not: { _id: someId }
,但是这给了我一个错误,说$not
无效。
$not
,您应该指定运算符:Product.find({ _id: {$not: {$eq: someId}}})
- Ron537