How can a find() access a document field for an operation? (MongoDB, nodeJS)

Viewed 58

hello I would like to know if daily_price > = price_clic * number_view

Model.find({

 daily_price: { 

  $gte: price_clic * number_view

 }

})

const schema = mongoose.Schema({

  price_clic: { type: Number, required: true },
  number_view: { type: Number, required: true, default: 0 },
  daily_price: { type: Number, default: 0 },

})

thank you so much

1 Answers

The following code solved my problem:

$expr: {

  $gte: [
    "$daily_price", { $multiply: ["$price_clic", "$number_view"] },
  ],
},

Related