使用mongoimport将日期(ISODate)导入MongoDB

Dis*_*ana 8 mongodb

我有这些MongoDB文件.在JSON中:

{
"attString":"hello World0",
"attInt":0,
"attDate":new Date("1990-7-20")
 }
Run Code Online (Sandbox Code Playgroud)

如何使用mongoimport?将此文档导入MongoDB ?我的attDate字段有问题.

这是MongoDB shell的通知:

失败:文档#1上的错误解组字节:意外的ISODate格式

Roh*_*ain 21

您必须在JSON中更改日期格式

{"attString":"hello World0","attInt":0,"attDate":ISODate("2013-11-20T23:32:18Z")}
Run Code Online (Sandbox Code Playgroud)

要么

{"attString":"hello World0","attInt":0,"attDate":{$date:"2013-11-20T23:32:18Z"}} 
Run Code Online (Sandbox Code Playgroud)

希望它会有所帮助

  • 这些解决方案不是有效的 json... 有什么建议可以纠正这个问题吗? (6认同)
  • 是的,“$date”从 MongoDB 被正确识别并且是有效的 JSON (6认同)
  • `$ date`为我工作,'ISODate`没有 - 谢谢! (3认同)