我有一些数据可以转换为json,因此可以导入mongodb。
对于某些文件,我们需要一个位于1970年之前的日期字段。 所以我们通过基本上这样做来测试文档:
[nbasjes@localhost ~]$ echo 'db.datetest.save({"date": new Date(1)});' | mongo nielsbasjes
MongoDB shell version: 2.0.6
connecting to: nielsbasjes
bye
[nbasjes@localhost ~]$ echo 'db.datetest.save({"date": new Date(-1)});' | mongo nielsbasjes
MongoDB shell version: 2.0.6
connecting to: nielsbasjes
bye
并插入了两个文件。
但是当我们尝试使用mongoimport加载相同的文档时,我们得到了这个:
[nbasjes@localhost ~]$ echo '{"date": new Date(1)}' | mongoimport -vv -d nielsbasjes -c datetest
Thu Jun 21 17:43:19 creating new connection to:127.0.0.1
Thu Jun 21 17:43:19 BackgroundJob starting: ConnectBG
Thu Jun 21 17:43:19 connected connection!
connected to: 127.0.0.1
Thu Jun 21 17:43:19 ns: nielsbasjes.datetest
Thu Jun 21 17:43:19 filesize: 0
Thu Jun 21 17:43:19 got line:{"date": new Date(1)}
Thu Jun 21 17:43:19 got line:
imported 1 objects
到目前为止一直很好......
[nbasjes@localhost ~]$ echo '{"date": new Date(-1)}' | mongoimport -vv -d nielsbasjes -c datetest
Thu Jun 21 17:43:24 creating new connection to:127.0.0.1
Thu Jun 21 17:43:24 BackgroundJob starting: ConnectBG
Thu Jun 21 17:43:24 connected connection!
connected to: 127.0.0.1
Thu Jun 21 17:43:24 ns: nielsbasjes.datetest
Thu Jun 21 17:43:24 filesize: 0
Thu Jun 21 17:43:24 got line:{"date": new Date(-1)}
Thu Jun 21 17:43:24 Assertion: 10340:Failure parsing JSON string near: "date": ne
0x581a82 0x528610 0xaa3ff3 0xaa5e63 0xa9cccd 0xaa0932 0x3bbb81ecdd 0x4fed69
mongoimport(_ZN5mongo11msgassertedEiPKc+0x112) [0x581a82]
mongoimport(_ZN5mongo8fromjsonEPKcPi+0x3d0) [0x528610]
mongoimport(_ZN6Import8parseRowEPSiRN5mongo7BSONObjERi+0x8b3) [0xaa3ff3]
mongoimport(_ZN6Import3runEv+0x16e3) [0xaa5e63]
mongoimport(_ZN5mongo4Tool4mainEiPPc+0x169d) [0xa9cccd]
mongoimport(main+0x32) [0xaa0932]
/lib64/libc.so.6(__libc_start_main+0xfd) [0x3bbb81ecdd]
mongoimport(__gxx_personality_v0+0x3c9) [0x4fed69]
exception:Failure parsing JSON string near: "date": ne
Thu Jun 21 17:43:24 got line:
imported 0 objects
encountered 1 error
我们已经尝试了几个相同日期的语法,我们对所有这些形式都有相同的效果:
测试系统使用mengo-10gen-2.0.6-mongodb_1.x86_64和10gen RPM存储库中的mongo-10gen-server-2.0.6-mongodb_1.x86_64运行CentOS 64Bit。
我们如何解决这个问题? 或者这是mongoimport中应该报告的错误吗?