How do you use values from fields in comparison when executing queries?
Example from docs:
db.inventory.find( { qty: { $gt: 20 } } )
How can I use a field value from the document instead of 20, like so:
db.inventory.find( { qty: { $gt: field2 } } )
This is what I am trying to achieve:
var query = model.find();
var first = "field1";
var second = "field2";
query.where(first).gt(second);
Edit: I am building the query dynamicly, so I need to use the query-builder in mongoose.
Edid2: Thanks to the answer below, this is how I solved my problem:
query.where({$where: "this."+first+" > this."+second});