Here is the MongoDB query I am trying to reproduce:
I have verified that this query produces the correct output using the mongo shell. I try to query it using spring data like this:
However, this produces the following query:
How can I get spring data to produce the query as shown above?
Code:
db.myCollection.find({
$and: [
{'key.attributes': {$elemMatch: {'name': 'k1', 'value': 'kv1'}}},
{'key.attributes': {$elemMatch: {'name': 'k2', 'value': 'kv2'}}}
]
})
Code:
where("key.attributes").elemMatch(where("name").is("k1").and("value").is("kv1"))
.andOperator(
where("key.attributes").elemMatch(where("name").is("k2").and("value").is("kv2"))
);
Code:
{ "key.attributes" : { "$elemMatch" : { "name" : "k1" , "value" : "kv1"}} , "$and" : [ { "key.attributes" : { "$elemMatch" : { "name" : "k2" , "value" : "kv2"}}}]}