Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6170

Mongoimport unable to load Date before epoch

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0.6
    • Component/s: Tools
    • Labels:
    • Environment:
      The test system runs CentOS 6.2 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.
    • ALL

      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.

      Here I document this issue simply with 1 millisecond before and after epoch.

      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")

            Assignee:
            Unassigned Unassigned
            Reporter:
            nielsbasjes Niels Basjes
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: