italktothewind
italktothewind

Reputation: 2195

MongoDB with Spring Data - Avoid $and operator

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

Answers (1)

s7vr
s7vr

Reputation: 75934

Use and(String key).

Something like

Criteria andCriteria = Criteria.where("someField").is("someValue").and("otherField").is("otherValue");

Upvotes: 1

Related Questions