I have migrated the collection.bson file from MongoDB 2.4 to MongoDB 3.6.4 as collection.json.

But their is 1 more file collection.metadata.json in MongoDB 2.4.

How can I import this to MongoDB 3.6.4?

content of collection.metadata.json is as below;

  "options": {
    "create": "collection"
  "indexes": [
      "v": 1,
      "name": "_id_",
      "key": {
        "_id": 1
      "ns": "emgda.collection"
      "v": 1,
      "name": "customerId_1_elementId_1_siteId_1_createdTimestamp_1",
      "key": {
        "customerId": 1,
        "elementId": 1,
        "siteId": 1,
        "createdTimestamp": 1
      "ns": "emgda.collection",
      "background": true,
      "sparse": true

mongorestore version is as below,

emgda@ubuntu:~/trial$ mongorestore --version
mongorestore version: r3.6.4
git version: d0181a711f7e7f39e60b5aeb1dc7097bf6ae5856
Go version: go1.7
   os: linux
   arch: amd64
   compiler: gc
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016

NOTE: When I use mongoretore -d emgda auditing.bson, I get below error for the collection.

checking for collection data in auditing.bson
reading metadata for emgda.auditing from auditing.metadata.json
Failed: emgda.auditing: error creating collection emgda.auditing: error running create command: BSON field 'OperationSessionInfo.create' is a duplicate field
  • 1
    How did you import collection.bson into MongoDB -- you mention importing as collection.json? If you imported using mongorestore, the associated metadata file should have been processed. If the secondary index wasn't created, the most straightforward approach would be to connect to the target database (emgda?) using the mongo shell and then build the index in the background with the same options: db.collection.createIndex({"customerId": 1, "elementId": 1, "siteId": 1, "createdTimestamp": 1}, { background:true, sparse: true}).
    – Stennie
    Commented Apr 2, 2019 at 9:59
  • @Stennie: Updated my post with error that I get when I directly use mongorestore
    – Ankur Soni
    Commented Apr 2, 2019 at 10:05
  • @AnkurSoni, Could you update mongorestore command, through which you are going to restore the collection.bson dump file. Commented Apr 2, 2019 at 10:23
  • Can you edit your post to include the output mongorestore --version? Do you know what version of mongodump was used? The error message indicates the collection create option is being passed twice, so I expect deleting the line "create": "collection" will allow your version of mongorestore to process the metadata.json.
    – Stennie
    Commented Apr 2, 2019 at 10:33
  • @stennie: updated
    – Ankur Soni
    Commented Apr 2, 2019 at 10:46

1 Answer 1


I had to manually remove "options": { "create": "collection" }, from *.metadata.json file and rest worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.