Get distinct values from array based on conditions within the array
问题 I have a collection with documents like this: { "_id" : ObjectId("59df91dae4b03289d79efb4e"), "name" : "TEST", "payload" : [ { "_id" : "ABC", "status": "FALSE" }, { "_id":"DEF", "status": "TRUE" }, { "_id" : "XYZ", "status": "NULL" } ] } I am trying to find all the payload._id which have status as TRUE/FALSE. Expected result is ["ABC","DEF"] So far, I have something like this. db.collection.distinct('payload._id',{"_id" : "TEST"}) Not sure how to add conditions for elements within array. 回答1: