Mongodb – Import indexes from MongoDB v2.4 to MonDB v3.6.4

mongodbmongodb-3.6mongodb2.4

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

Best Answer

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