Reputation: 2195
I want to create the following query using MongoDB api for Spring Data:
{ "someField": "someValue", otherField: "otherValue"}
The only way I found to do this is:
Criteria someFieldCriteria = Criteria.where("someField").is("someValue");
Criteria otherFieldCriteria = Criteria.where("otherField").is("otherValue");
Criteria andCriteria = new Criteria.andOperator(someFieldCriteria, otherFieldCriteria)
But this compiles to:
{ $and: [{ "someField": "someValue"}, { otherField: "otherValue"}] }
Anyone knows? Thanks!
Upvotes: 0
Views: 535
Reputation: 75934
Use and(String key)
.
Something like
Criteria andCriteria = Criteria.where("someField").is("someValue").and("otherField").is("otherValue");
Upvotes: 1