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 ?
答案 0 :(得分:0)
当MongoDB / Mongoose序列化对象时,它会将其转换为JSON。
JSON值只能是object,array,number,string,true,false或null类型。查看ECMA-404 The JSON Data Interchange Format第5部分或Douglas Crockford的JSON网站。
鉴于我们知道它只能是上述值之一,我们知道mongoose将其序列化为字符串。将它转换为实际的JavaScript日期对象是你的工作。您可以手动获取日期并自行解析,也可以使用像moment.js这样的库来处理大部分解析/格式化和其他与日期相关的函数。
另请参阅其他可能对您有帮助的StackOverflow问题。