1
votes

I want to query that returns document that two fields of it are equal

I found mongodb raw query from this question :

db.coll.find({ $where : "this.field1 == this.field2" } );

How can I perform it with spring criteria:

criteria = criteria.andOperator(
            Criteria.where("successfulSent").is("true"),
            Criteria.where("this.fieldOne == this.fieldTwo"));

but its not working beacuse generated query become :

  { ... "$and" : [ { "successfulSent" : "true"} , { "this.fieldOne == this.fieldOne " : { }}]}
1
What is your mongo version ? - s7vr
@Veeram mongo 3.6 - mohsenJsh

1 Answers

2
votes

You can try on this way:

Criteria.where("$where").is("this.field1 == this.field2")

Query toString() will be:

Query: { "$where" : "this.cts == this.uts"}, Fields: null, Sort: null