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

mongoimport fails to import an empty JSON array

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 100.7.0
    • Component/s: mongoimport
    • Environment:
      OS: Ubuntu 22.04
    • 563
    • Not Needed

      Problem Statement/Rationale

      mongoimport fails when importing an empty JSON array, and emits an error. Instead, it should successfully import 0 records and exit.

      Steps to Reproduce

      1. Create file empty-json-array.json, with contents []
      2. Replace placeholders as appropriate, then run:
         
        mongoimport --uri <uri> --db <db> --collection <collection> --type json --jsonArray --file empty-json-array.json

         

        Expected Results

      A successful import with no errors reported

      Actual Results

      Failed: error processing document #1: invalid character ']' looking for beginning of value

      Additional Notes

      Version:

      mongoimport version: 100.7.0
      git version: 17946f45f5fabfcdd99f8960b9109f976d370631
      Go version: go1.19.3
         os: linux
         arch: amd64
         compiler: gc 

      Solution

      We will make mongoimport accept a file with an empty JSON array in it. When it encounters such a file, it will log a message saying that this file will be skipped because it does not contain any documents. This message will be logged at the Info level.

            Assignee:
            Unassigned Unassigned
            Reporter:
            paul@unlikely.ai Paul Benn
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: