0
    {
    "_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
                }
            ]
        }
    ]
}

From this document I want to fetch spyneShareUsers list.

Can some one please help me with it,

  • top id = 575
  • inner id = fxLO68XyMR

I want the list of objects that content email id and a boolean value.

Please help me to get the data.

Mr Freak
  • 216
  • 3
  • 20

1 Answers1

1

Using Mongo aggregation pipeline you can collect the document data as you want. Try this:

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