4
db.collection.aggregate([
    {$addFields : {newDateField : {$toDate : {$multiply : ["$date", 1000]}}}},
    {$match : {newDateField: {$lte: new Date(), $gte: new Date(ISODate().getTime() - 1000 * 86400 * 30)}}}])

In the above query, I am trying to get all events that happened in the past 30 days (from now). In the shell, the query runs smoothly. However, I need to convert it to JSON extended. That means that I need to use $date keyword instead of new Date() as the documentation requires. If anyone knows how to do this, I would appreciate it.

hot_zera
  • 41
  • 2

0 Answers0