I\'m generating a complicated Mongo
query depending on multiple parameters. One of criterion that I want to make with Criteria
helper class is:
Since you can’t use Criteria.and() to add multiple criteria into the same field, use Criteria.andOperator() as follows:
Query query = new Query();
query.addCriteria(
new Criteria().andOperator(
Criteria.where("field1").exists(true),
Criteria.where("field1").ne(false)
)
);
List result = mongoTemplate.find(query, Foo.class);
System.out.println("query - " + query.toString());
for (Foo foo : result) {
System.out.println("result - " + foo);
}