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

mongorestore won't restore manually edited .metadata.json file if user editor adds trailing newline

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.4.2, 2.5.0
    • Affects Version/s: 2.2.3, 2.4.1
    • Component/s: Tools
    • None
    • ALL

      SERVER-6947 describes an issue where collections created with createCollection are dumped incorrectly with all mongodump 2.2.x/2.4.x versions currently released. The incorrect dumps are characterized by invalid options present in the JSON metadata file for these collections.

      One known workaround for this issue is to manually edit the JSON metadata files to correct the invalid options (note: another known workaround is to restore with mongorestore >=2.4). However, this workaround has a flaw. The JSON metadata files are created without trailing newlines; however, when users attempt to edit these files to implement the workaround, their editors will often add trailing newlines.

      Restoring with these edited metadata files trips a fatal assertion in mongo::Restore::parseMetadataFile, which checks that there are no bytes in the file past the end of the first encountered JSON object. This check fails because of the trailing newline. The assertion generates the unhelpful message "JSON object size didn't match file size".

      Reproduce with:

      rassi@laptop:~/dist/mongodb-osx-x86_64-2.4.1/bin $ ./mongo --eval 'db.dropDatabase()'
      MongoDB shell version: 2.4.1
      connecting to: test
      [object Object]
      rassi@laptop:~/dist/mongodb-osx-x86_64-2.4.1/bin $ ./mongo --eval 'db.foo.insert({})'
      MongoDB shell version: 2.4.1
      connecting to: test
      rassi@laptop:~/dist/mongodb-osx-x86_64-2.4.1/bin $ ./mongodump -d test
      connected to: 127.0.0.1
      Fri Mar 29 16:09:32.127 DATABASE: test	 to 	dump/test
      Fri Mar 29 16:09:32.129 	test.system.indexes to dump/test/system.indexes.bson
      Fri Mar 29 16:09:32.130 		 1 objects
      Fri Mar 29 16:09:32.131 	test.foo to dump/test/foo.bson
      Fri Mar 29 16:09:32.132 		 1 objects
      Fri Mar 29 16:09:32.133 	Metadata for test.foo to dump/test/foo.metadata.json
      rassi@laptop:~/dist/mongodb-osx-x86_64-2.4.1/bin $ echo >> dump/test/foo.metadata.json
      rassi@laptop:~/dist/mongodb-osx-x86_64-2.4.1/bin $ ./mongo --eval 'db.dropDatabase()'
      MongoDB shell version: 2.4.1
      connecting to: test
      [object Object]
      rassi@laptop:~/dist/mongodb-osx-x86_64-2.4.1/bin $ ./mongorestore
      connected to: 127.0.0.1
      Fri Mar 29 16:09:54.016 dump/test/foo.bson
      Fri Mar 29 16:09:54.017 	going into namespace [test.foo]
      assertion: 15934 JSON object size didn't match file size
      rassi@laptop:~/dist/mongodb-osx-x86_64-2.4.1/bin $
      

            Assignee:
            rassi J Rassi
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: