A test collection has one document.
db.test.insert({
"_id" : ObjectId("5922bd14ff3ee9313229ac18"),
"O" : [
{
"A" : "Field_1",
"B" : "Unknown"
},
{
"A" : "Field_2",
"B" : "Unknown_Location"
}
]
})
I want this entry to return only if both the A and the B filter's match in one of the documents.
For example, TEST CASE 1:
db.test.find({"O.A" : "Field_2", "O.B" : "Unknown_Location"}).count()
1
db.test.find({"O.A" : "Field_1", "O.B" : "Unknown"}).count()
1
TEST CASE 2 But the following query also returns this entry, for which causes problems:
db.test.find({"O.A" : "Field_1", "O.B" : "Unknown_Location"}).count()
1
Help is sincerely appreciated.
This question is different from Retrieve only the queried element in an object array in MongoDB collection In that question, the question was to retrieve a part and was solved by projecting a part of matched document.
My Problem is that the match in the TEST CASE 2 is unwanted and I need to change my query accordingly.