$ 9加上$和猫鼬

$nin with $and in mongoose

本文关键字:加上      更新时间:2023-09-26

使用猫鼬操作筛选用户(admin)

他需要看到所有保存的文件…

但是他应该能够再次看到他自己保存的草稿文件…

代码:

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).)*$/}]})