且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JavaScript-如何以ISODate格式在MongoDB文档中保存日期?

更新时间:2021-11-09 22:14:48

我通过在Node JS API端进行处理来解决了这个问题.真正的问题是我已经将其作为字符串化的JSON对象发送到API.尽管它被设置为新的Date()对象,但它却被字符串化了.

I solved this by handling this in my Node JS API side. The real problem is I've been sending this to the API as an stringified JSON object. though it was set as a new Date() object it get stringified.

因此,在将它插入MongoDB集合之前,在Node JS API方面,我已经完成了

So within my Node JS API side before inserting it into the MongoDB collection I've done this,

var data = req.body.postData;
var date = data[0].date;
var dateObject = new Date(date);
date[0].date = dateObject;

哪个骗人的!感谢您的回答!

Which did the trick! Thanks for the answers!