So, for some reason the developers decided to store some information using dynamically named nested fields, and now the queries on these fields are (not surprisingly) sluggish.
The documents are like so:
{
"_id:" : "2343244324",
"field" : {
"nested_9j3kj49j" : {
// some other stuff here
},
"nested_j32kj43" : {
// yet some other stuff here
}
},
[other fields]
}
***
{
"_id:" : "57657656",
"field" : {
"nested_687fds6d7f6" : {
// and yet some other stuff here
}
},
[other fields]
}
The mentioned slow queries are something like this:
db.Collection.find({ "field.nested_j32kj43" : { $exists: true} });
Is there anyway I could do this query in a more optimized way, or maybe create some sort of index to those nested fields, which vary in name and existence?