2015-10-13 119 views
5

我有這些MongoDB文檔。在JSON中:使用mongoimport將日期(ISODate)導入MongoDB

{ 
"attString":"hello World0", 
"attInt":0, 
"attDate":new Date("1990-7-20") 
} 

如何使用mongoimport將此文檔導入到MongoDB中?我與attDate字段有問題。

這是MongoDB的外殼通知:

失敗:對文件#1錯誤拆封字節:意外ISODate 格式

+0

的可能的複製[JSON文件Mongoimport(http://stackoverflow.com/questions/15171622/mongoimport-of-json-file) – Pio

回答

12

你必須改變你的日期格式JSON

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

OR

{"attString":"hello World0","attInt":0,"attDate":{$date:"2013-11-20T23:32:18Z"}} 

希望這將有助於

+0

完美,謝謝。 – DistribuzioneGaussiana

+2

'$ date'爲我工作,'ISODate'沒有 - 謝謝! – CodingIntrigue

+0

我發現這是因爲我遇到類似的錯誤。我發現MongodDB 3.4支持'ISODate',但不支持2.6。 '$ date'在兩者都支持。 –

相關問題