Unable to get Current Date in MongoDB View Query

We have meteor app and we’re using mongodb as database. Now, since the VIEW feature is already available on mongodb we tried to use it to generate a report. However, we are having issue on comparison to our collection date field and to the current date, we cannot even retrieved current date field using mongodb aggregate under $project because we don’t know the right syntax to get the current date. Our goal is since it’s using view we would like to replace new Date() (which is the today’s date in below codes) to the current date method of mongodb.

"waiting_for_appointment" : {
            $cond : {
                if: { $eq: ["$current_status", "Waiting For Appointment"]},
                then: {
                    $cond : {
                         if: {$gt: [{$subtract: [ new Date(), "$statuses.waiting_for_appointment.from_date" ]}, 0]},
                         then: {
                            $cond: {
                                if: {$gt: [{$subtract: [ "$statuses.waiting_for_appointment.to_date", "$statuses.waiting_for_appointment.from_date" ]}, 0]},
                                then: {$multiply : [{
                                    $divide: [{$subtract: [ new Date(), "$statuses.waiting_for_appointment.from_date" ]}, {$subtract: [ "$statuses.waiting_for_appointment.to_date", "$statuses.waiting_for_appointment.from_date" ]}]
                                    }, 100]
                                },
                                else: 0
                            }
                         },
                         else: 0
                    }
                },
                else: -1
            }
        },

The query works correctly but when I edit again the VIEW query I found that it is converted to static date, the date when was the query is saved. This is what we got after saving the query and editing it back.

ISODate("2017-10-09T02:12:42.282+0000")

That’s why, the query will not be effective if the date is changed.

Thanks in advance.

0 Comment

NO COMMENTS

LEAVE A REPLY

Captcha image