如何从 mongo 获取嵌套数组列表?

How to fetch nested array list from mongo?

    {
    "_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 布尔值 值的对象列表。

请帮我获取数据。

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

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