【问题标题】:How to fetch nested array list from mongo?如何从 mongo 获取嵌套数组列表?
【发布时间】:2020-05-26 16:49:53
【问题描述】:
    {
    "_id" : "575",
    "_class" : "com.spyne.sharing.SpyneShareUserProject",
    "spyneSharePhotoList" : [ 
        {
            "_id" : "fxLO68XyMR",
            "spyneShareUsers" : [ 
                {
                    "_id" : "chittaranjan@eventila.com",
                    "selectedByClient" : false
                }, 
                {
                    "_id" : "chittaranjan@gmail.com",
                    "selectedByClient" : false
                }
            ]
        }, 
        {
            "_id" : "nVpD0KoQAI",
            "spyneShareUsers" : [ 
                {
                    "_id" : "chittaranjan@eventila.com",
                    "selectedByClient" : true
                }
            ]
        }, 
        {
            "_id" : "Pm0B3Q9Igv",
            "spyneShareUsers" : [ 
                {
                    "_id" : "chittaranjan@gmail.com",
                    "selectedByClient" : true
                }
            ]
        }
    ]
}

我想从这个文档中获取 spyneShareUsers 列表。

谁能帮帮我,

  • 顶部 ID = 575
  • 内部 id = fxLO68XyMR

我想要包含 email idboolean 值的对象列表。

请帮我获取数据。

【问题讨论】:

    标签: arrays mongodb mongodb-query aggregate mongotemplate


    【解决方案1】:

    使用 Mongo 聚合管道,您可以根据需要收集文档数据。试试这个:

    db.collection.aggregate([
      {
        $unwind: {
          path: "$spyneSharePhotoList"
        }
      },
      {
        $match: {
          _id: "575",
          "spyneSharePhotoList._id": "fxLO68XyMR"
        }
      },
      {
        $project: {
          _id: 1,
          spyneShareUsers: "$spyneSharePhotoList.spyneShareUsers"
        }
      }
    ])
    

    【讨论】:

    • 我得到 ** 在 0 毫秒内获取 0 条记录 **
    • 您是否在此处替换了您的收藏名称:db.collection.aggregate()
    • 好的,谢谢,我犯了你提到的错误。你能看看这个问题stackoverflow.com/questions/60182047/…
    猜你喜欢
    • 2021-12-14
    • 2020-09-27
    • 2018-04-18
    • 1970-01-01
    • 2012-03-08
    • 2023-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多