For below mongo document, I am trying to write a projection query. Given an input of userId value and ObectId of a target (ex: 54073d80e4b0cbf1ce225f02 in below document), how do I find the document which has these values?
All the examples, I searched expect the user to know the "property" names to query against. In this case, property names in "target" element are not known ahead of time. They can be my-target-1, my-target-2 etc. SO I want to search the document based on the value of the property (54073d80e4b0cbf1ce225f02). Any suggestions?
{
"_id" : ObjectId("540786bbe4b0e4752fe93321"),
"name" : "foo name",
"userId" : "123456",
"targets" : {
"my-target-1" : { //my-target-1 is dynamic property.
"executionOrder" : {
"1" : { //"1" is dynamic property.
"_id" : ObjectId("54073d80e4b0cbf1ce225f02"),// this is my search key
"type" : "TYPE 1",
"version" : "2"
},
"2" : {
"_id" : ObjectId("54073d80e4b0cbf1ce225f03"),
"type" : "TYPE 2",
"version" : "2"
}
}
},
"my-target-2" : {
"executionOrder" : {
"1" : {
"_id" : ObjectId("54073d80e4b0cbf1ce225f04"),
"type" : "TYPE 1",
"version" : "2"
},
"2" : {
"_id" : ObjectId("54073d80e4b0cbf1ce225f05"),
"type" : "TYPE 2",
"version" : "2"
}
}
}
},