Let me be straight with the question, OK I have document structure like
let the collection name be sample;
were i'll not be knowing the someIdAsString.
{
_id : ObjectId("someObjectId"),
test : {
someIdAsString : {
field1 : value1,
field2 : value2
},
someOtherIdAsString : {}
.....
.....
And so on
}
}
I have the field1 & field2 values how do i query the collection using this information.
field1 & field2 will be known at run time lets say it's field1 = '33' & field2 = '3333' and the document like
{
_id : ObjectId("522182515f8wea670900001b"),
test : {
522182515f8c4wd70900001b : {
field1 : '33',
field2 : '3333'
},
522182515f8cea670900001b : {}
.....
.....
And so on
}
}
Thanks
I suggest you to change the schema, so that this
someIdAsString
text becomes a value instead of a key, making the object intest
become a list of objects. If you know every key, you can tryFor all your "someIdAsString" possibilities.
If you change the structure to:
You can change the query to:
A workaround to use a query while still using your data structure without knowing the embedded key names would be a JavaScript in a $where operator.