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
collection.bson
into MongoDB -- you mention importing ascollection.json
? If you imported usingmongorestore
, 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 themongo
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 Apr 2 '19 at 9:59mongorestore
– Ankur Soni Apr 2 '19 at 10:05mongorestore --version
? Do you know what version ofmongodump
was used? The error message indicates the collectioncreate
option is being passed twice, so I expect deleting the line"create": "collection"
will allow your version ofmongorestore
to process the metadata.json. – Stennie Apr 2 '19 at 10:33