Jester
Jester

Reputation: 3329

how to convert a mongodb date field that is isodate to local date

I have a aggregation pipeline like:

db.Collection.aggregate([{
              $project:{
                    Name:1,
                    ModDate: new Date("$history.ModDate")
               }}])

I tought that Date would convert it to local time but I get the default value of: 1970-01-01 00:00:00.000Z

Even doh the value of the ModDate is something like:

2015-10-18 06:50:19.000Z

And ModDate on the history subdocument is a date field

Is there a way to convert the isodate to the server local date?

Upvotes: 1

Views: 1766

Answers (1)

DB user10082797
DB user10082797

Reputation: 38

Have you tried

ModDate: Date("$history.ModDate")

(i.e. without the new operator)

Upvotes: 1

Related Questions