Essentially, I want to query mongo return documents that contain matching keys from a partially defined json object.
Example document:
{
"description" : {
"body" : {
"type" : "Ectomorph",
"shape" : "Spoon",
"muscle tone" : "Moderately Tone"
}
}
}
How I'm attempting to query
db.taxonomy.find({ description: { $elemMatch: { body: { type: "Ectomorph" } } } })
Although, according to the mongo documentation $elemMatch
appears to be the operator i want to use, it doesn't appear to be working this way.
Note
I'm aware that the query would work if it was writting as { "decription.body.type": "Ectomorph" }
But the key values I'm searching by are coming from a request and i'd rather not waste processing power parsing the JSON into a query like this if i don't have to.