0

I want to compare the object keys in order to make decision, something like below.

Schema:

var ItemSchema = new Schema({
  price:      {type: Number},
  msrp:       {type: Number},
});

Query:

Note: This is just prototype of my intention and not a legal code.

Item.find({'(100 - ((price * 100)/msrp))' : {$gt: 60 }})

Where msrp and price inside $gt should be the values of the current element of find processing.

1 Answers1

2

You can use a $where operator. Just be aware that it will be fairly slow as it has to execute Javascript code for every record, so combine with indexed queries if you can. You can read more about the $where operator here

Item.find( { $where: function() { return this.price > 100-((this.price*100)/this.msrp) } } );
Mohammad Ali
  • 878
  • 8
  • 16