Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-899

mongoimport changes field order on custom IDs

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.0.4
    • Component/s: mongoimport
    • Environment:
      $ lsb_release -a
      No LSB modules are available.
      Distributor ID: Debian
      Description: Debian GNU/Linux 7.8 (wheezy)
      Release: 7.8
      Codename: wheezy

      When importing JSON files, mongoimport will randomly change the order of custom ID fields. Specifically, documents exported with mongoexport, then imported again with mongoimport will not end up identical. Since field order matters in mongoDB, these "shuffled" documents are not found anymore by our software, creating all kinds of problems. mongoimport is unusable for us as of now.

      To reproduce, import the attached JSON file:

      mongoimport -d test -c test --file test.json

      The result is different every time. Here's one example:

      > db.test.find();
      { "_id" :

      { "a" : "index", "b" : 1, "c" : 3 }

      , "d" : "test" }
      { "_id" :

      { "a" : "index", "b" : 1, "c" : 2 }

      , "d" : "test" }
      { "_id" :

      { "a" : "index", "b" : 2, "c" : 2 }

      , "d" : "test" }
      { "_id" :

      { "c" : 3, "a" : "index", "b" : 2 }

      , "d" : "test" }
      { "_id" :

      { "a" : "index", "b" : 3, "c" : 1 }

      , "d" : "test" }
      { "_id" :

      { "b" : 3, "c" : 2, "a" : "index" }

      , "d" : "test" }
      { "_id" :

      { "a" : "index", "b" : 1, "c" : 1 }

      , "d" : "test" }
      { "_id" :

      { "a" : "index", "b" : 2, "c" : 1 }

      , "d" : "test" }
      { "_id" :

      { "a" : "index", "b" : 3, "c" : 3 }

      , "d" : "test" }

      Notice line 4 and 6 where the field order is wrong.

      This behaviour was not observed in 2.x versions (although I cannot confirm at the moment).

        1. test.json
          0.4 kB
          Oliver

            Assignee:
            kyle.erf Kyle Erf
            Reporter:
            rivo Oliver
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: