0

My problem is that I've got objects with date property,and I want to filter by date in my front-end application (using angularJS).

but unfortunately the mongoose serialize the object as key-value strings example of object :

"_id":123456,
Name :"Adam",
Family: "Levine",
Date : ISODate("2017-02-22T22:00:00:00Z"),
"__v":0

but when Im do Model.find() mongoose function, Im get this object :

"_id":123456,
Name :"Adam",
Family: "Levine",
Date : "2017-02-22T22:00:00:00Z"

how can I fix that problem ?

black bamba
  • 57
  • 1
  • 3

1 Answers1

0

When MongoDB/Mongoose serializes the object it turns it into JSON.

JSON values can only be of type object, array, number, string, true, false or null. Check out the ECMA-404 The JSON Data Interchange Format Section 5 or Douglas Crockford's JSON site.

Given that we know it can only be one of the above values, we know that mongoose is serializing it into a string. It is your job to convert it into an actual JavaScript date object. You can either manually take the date and parse it yourself or you can use a library like moment.js that will handle much of the parsing/formatting and other date related functions for you.

Also take a look at some other StackOverflow questions that may help you.

Community
  • 1
  • 1
Aaron Conran
  • 321
  • 1
  • 6