Loading Date values before 1970 using mongoimport vs mongo shell

I have some data which we transformed into json so it can be imported into mongodb.

For some documents we need to have a date field that lies before 1970. So we tested the documents by essentially doing this:

[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

and two documents have been inserted.

However when we try to load the same documents using mongoimport we get this:

[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

So far so good ...

[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

We have tried several syntaxes for the same date and we get the same effect with all these forms:

  • {"date": new Date(-2174520376)}
  • {"date": new Date(1901,2,3,22,33,44,000)}
  • {"date": new Date("February 3, 1901 22:33:44")

The test system runs CentOS 64Bit with mongo-10gen-2.0.6-mongodb_1.x86_64 and mongo-10gen-server-2.0.6-mongodb_1.x86_64 from the 10gen RPM repository.

How do we solve this? Or is this a bug in mongoimport that should be reported?

Answers


I filed this as a bug in the MongoDB bug tracker. https://jira.mongodb.org/browse/SERVER-6170


Need Your Help

catch exceptions from all Pages

c# asp.net exception

I am trying to log all "general errors" from the site I am maintaining, to debug the code-behind, without having to show the detailed error page to the users. The web.config says:

How to access Active Record Object Values ? Ruby on Rails

ruby-on-rails object ruby-on-rails-4 activerecord model

I am relatively new with ruby on rails. I made a relationship called friendships, which has the following attributes: