【问题标题】:Exclude List of document in mongoose排除猫鼬中的文档列表
【发布时间】:2020-12-11 10:03:50
【问题描述】:

如何使用 mongoose 排除(使用 Id)集合中的文档列表。

User.find({}, function (err, docs) {

})

它提供了用户集合中的所有文档,但我需要从用户集合中排除文档列表

excludedUserId = ["234h2gl2422vb2c3sdf","sdf98sfd9sfdu978fsf","sfdsdf2325yh3432",......] //dummy User Id

【问题讨论】:

    标签: mongodb mongoose mongodb-query mongoose-schema mongoose-populate


    【解决方案1】:

    您可以使用$nin 字段运算符。示例:

    {_id:{$nin:[ObjectId('5f3de9dca1aaae489a9620e0'),...]}}
    

    【讨论】:

      猜你喜欢
      • 2015-10-01
      • 2019-06-06
      • 2016-08-17
      • 1970-01-01
      • 2019-07-19
      • 1970-01-01
      • 2020-06-10
      • 2022-11-24
      • 2020-08-10
      相关资源
      最近更新 更多