Suppose I create a document in a MongoDB collection with the following structure and command:
db.foo.insert(
{
"PatientCore" :
{ "Name" : "John Doe", "Age" : 30 },
"OnArrivalData" :
{
"Readings" :
{ "Temperature" : 100.1, "HBP" : 140, "LBP" : 88, "TimeStamp" : new Date() },
"Attending Doctor" : "Dr. Samuel John"
},
"TreatmentStage" :
[
{
"StageName" : "Surgery",
"Readings" :
[
{ "Temperature" : 100.1, "HBP" : 130, "LBP" : 70, "TimeStamp" : new Date() },
{ "Temperature" : 99.1, "HBP" : 120, "LBP" : 70, "TimeStamp" : new Date()
],
},
{
"StageName" : "ICU",
"Readings" :
[
{ "Temperature" : 99, "HBP" : 135, "LBP" : 72, "TimeStamp" : new Date() },
{ "Temperature" : 98.6, "HBP" : 141, "LBP" : 80, "TimeStamp" : new Date() }
],
}
]
}
)
Firstly, please note that I have multiple occurrences of “Readings” in the document.
I want to query “Readings” across the document in such a way that I don’t have to qualify it with the reference to the embedded document. How can I achieve this? We can assume that the structure of “Readings” will be consistent.
I know that I can also work towards re-structuring the document, but here I don’t have the liberty to do so.
That is currently not possible as it would require MongoDB to understand field name wildcards. It would have to allow things like
{'*.Readings.Temperature': 99}which it does not at time of writing.Ther feature request is here https://jira.mongodb.org/browse/SERVER-267