使用 Mongoose 操作过滤用户(管理员)。
他需要查看所有已保存的文件...除了草稿文件..
但他应该能够再次看到自己保存的草稿文件...
代码:
filter = {
'_id':
$nin://not in (dont show)
[{
$and:
[
// {_id : _id},//in this id and
{createBy: {$ne: userId}},//other dan admin and
{status: {$regex: /draft/, $options: 'm'}} //save as draft
]
}]
}
我尝试以这种方式进行过滤,但最终出现此错误..
exceptionMongoError: Can't canonicalize query: BadValue unknown top level operator: $nin
提前致谢...
最佳答案
您只需要查找用户创建的文档或非草稿的文档:
files.find({$or: [{createBy: userId}, {status: /^((?!draft).)*$/}]})
关于javascript - $nin 与 $and 在 Mongoose 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39264867/