0

Is it possible in mongoDB to query documents where a field's value is greather than another one of the same document ?

I want to query each document where a > b for documents as:

{
 a: Number,
 b: Number,
}

Is it possible to reference a field's value in query to another one ?

Gp2mv3
  • 1,435
  • 20
  • 33

1 Answers1

0

Yes it is possible. Consider that you are trying to get the documents where a is greater than b. The code below is doing that.

db.collectionName.find({$where: "this.a > this.b"})