0

I've documents as follows:

{
   id: "14530529:V10AFRIN2018-AED15C",
   daily_log:{
      downloaded: 12345,
      uploaded:   10000,
      total:      50000
   }
}

I need to find documents if sum of daily_log.downloaded and daily_log.uploaded is greater than 80% percentage of daily_log.total

  • What is your mongo version ? – s7vr Jan 24 '18 at 11:55
  • You can try `db.col.find({"$expr":{"$gt":[{"$add":["daily_log.downloaded", "daily_log.uploaded"]}, {"$multiply":[0.8, "$daily_log.total"]}]}});` in 3.6 – s7vr Jan 24 '18 at 11:57
  • Thank you @Veeram. Do you have a suggestion for MongoDB 3.2? – şafak çırağ Jan 24 '18 at 13:06
  • Np.Wrap the logic in [`$redact`](https://docs.mongodb.com/manual/reference/operator/aggregation/redact/) from aggregation. Something like `db.col.aggregate({ $redact: { $cond: { if: {"$gt":[{"$add":["daily_log.downloaded"‌​, "daily_log.uploaded"]}, {"$multiply":[0.8, "$daily_log.total"]}]}, then: "$$KEEP", else: "$$PRUNE" } } })` – s7vr Jan 24 '18 at 13:10

0 Answers0