Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongorestore metadata.json file

I have a .bson file from a MongoDB dump. The dump also produces a .metadata.json file that seems to contain index definitions.

{
    "options": {},
    "indexes": [
        {
            "v": 1,
            "key": {
                "_id": 1
            },
            "name": "_id_",
            "ns": "test.oneMillionDocuments"
        }
    ]
}

I assume from this that restoring from the .bson file doesn't include the indexes.

  • How do I use the .metadata.json file? Do I need to restore it separately?

My restore finished with the following lines:

2016-02-06T19:18:56.397+0000    [#######################.]  test2.oneMillionRecordsRestore  9.7 GB/9.7 GB  (99.5%)
2016-02-06T19:18:58.475+0000    restoring indexes for collection test2.oneMillionRecordsRestore from metadata
2016-02-06T19:18:58.485+0000    finished restoring test2.oneMillionRecordsRestore (1000000 documents)
2016-02-06T19:18:58.488+0000    done

There's a line saying it's restoring the indexes, but specifically referencing the .metadata.json file.

like image 237
BanksySan Avatar asked Feb 06 '16 19:02

BanksySan


People also ask

How do I restore a JSON file in MongoDB?

Open the Import Wizard. Then, choose JSON as the import format and click OK. Click on + to add JSON source documents, – to remove them, or the clipboard icon to paste JSON data from the clipboard. Here we will add the JSON source document, Rainfall-Data.

Does Mongorestore overwrite data?

However, mongorestore performs inserts only and does not perform updates. That is, if restoring documents to an existing database and collection and existing documents have the same value _id field as the to-be-restored documents, mongorestore will not overwrite those documents.

What is Mongodump and Mongorestore?

Database backup is a copy of a database that already exists. In MongoDB, mongodump tool is used to take the data backup. And mongorestore tool is used to restore the backup data.


1 Answers

You don't have to do anything specific with the metadata.json file: just run mongorestore and it will be read together with the .bson files provided that it is in the same directory. You will see a line in the output from which you can infer whether it has been read or not:

2016-02-06T20:22:08.652+0100    reading metadata for mydb.message from dump/mydb/message.metadata.json

However, I think that there are cases where it is ignored (e.g. conflicting index definitions). The import won't fail though, but you will see a line in the log telling you that the metadata (or parts of it) were ignored.

like image 81
Nicolas Avatar answered Oct 13 '22 03:10

Nicolas