【问题标题】:filtering document in mongoose based on id and one specific property根据 id 和一个特定属性过滤 mongoose 中的文档
【发布时间】:2021-05-26 19:15:13
【问题描述】:

只是停留在如何根据 user_id 和 popupsArray.isSeen = true 过滤下面的文档。

enter image description here

我想从 isSeen = FALSE 的 popupsArray 中获取弹出窗口

【问题讨论】:

  • 你能分享架构细节并添加问题代码吗?

标签: node.js mongodb mongoose


【解决方案1】:

欢迎来到 SO。我们不建议您发布图片,而是您需要在 sn-ps 中发布您的代码。您可以简单地使用$filter in aggregation

db.collection.aggregate([
  {
    $set: {
      popupsArray: {
        "$filter": {
          "input": "$popupsArray",
          "cond": {
            $eq: [
              "$$this.isSeen",
              false
            ]
          }
        }
      }
    }
  }
])

工作Mongo playground

【讨论】:

    猜你喜欢
    • 2015-03-23
    • 2016-02-20
    • 2019-06-25
    • 2015-08-08
    • 2016-01-07
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 2019-08-19
    相关资源
    最近更新 更多