【问题标题】:$nin with $and in mongoose$nin 和 $and 在猫鼬中
【发布时间】:2016-09-07 22:11:17
【问题描述】:

使用猫鼬操作过滤用户(管理员)。

他需要查看所有保存的文件……除了草稿文件……

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

代码:

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

提前谢谢...

【问题讨论】:

    标签: javascript node.js mongodb mongoose


    【解决方案1】:

    您只需要找到用户创建的文档或非草稿的文档:

    files.find({$or: [{createBy: userId}, {status: /^((?!draft).)*$/}]})

    【讨论】:

    • 我的代码就是这样做的。正则表达式用于显示那些不是草稿的。
    • 我的 createBy 字段名称有误。固定的。再试一次。
    猜你喜欢
    • 2016-02-21
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 2012-01-17
    • 2013-06-21
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多