Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore data Mongodb from JSON

Tags:

mongodb

I have a dump which including 2 files data.json and metadata.json. I need restore this data on my local pc, I tried used mongorestore tool, but it don't helped me

like image 305
Jack Avatar asked Mar 23 '15 11:03

Jack


People also ask

How do I import a JSON file into MongoDB?

To import JSON file you need to follow the following steps: Step 1: Open a command prompt and give command mongod to connect with MongoDB server and don't close this cmd to stay connected to the server. Step 2: Open another command prompt and run the mongo shell. Using the mongo command.

How do I restore a collection in MongoDB?

To restore a single database or a collection (or specific documents) from a snapshot, you can use the Queryable Backup to export a single database or collection to restore to the target deployment.

How the data in MongoDB can be backup and restore?

In MongoDB, mongorestore utility is used to restore the backup data. It restores the binary backup created by mongodump utility(i.e., BSON data dumps). It can restore either an entire database backup or a subset of the backup. It also restores the indexes which are created for any collection inside that database.

Can JSON be stored in MongoDB?

Does MongoDB use BSON or JSON? MongoDB stores data in BSON format both internally, and over the network, but that doesn't mean you can't think of MongoDB as a JSON database. Anything you can represent in JSON can be natively stored in MongoDB, and retrieved just as easily in JSON.

How to restore a MongoDB database using command line?

In order to restore a MongoDB database, we need to use mongorestore, a command line utility for restoring a MongoDB database. We can use the following C# .NET method and the appsettings.json file from above to get it done.

How do I backup BSON data in MongoDB?

The mongorestore and mongodump utilities work with BSON data dumps, and are useful for creating backups of small deployments. For resilient and non-disruptive backups, use a file system or block-level disk snapshot function, such as the methods described in the MongoDB Backup Methods document.

How to restore a database with a saved snapshot in MongoDB?

You can pass a query into mongodump using the --query parameter so that you, in case of a failure, are able to use some kind of timestamp/ordering field in your collection to resume the backup process. In order to restore a database with a saved snapshot, we just have to use the mongorestore command.

How do I import JSON into MongoDB?

The process to import JSON into MongoDB depends on the operating system and the programming language you are using. However, the key to importing is to access the MongoDB database and parsing the file that you want to import.


1 Answers

The mongorestore program writes data from a binary database dump created by mongodump to a MongoDB instance. While, mongoimport tool provides a route to import content from a JSON, CSV, or TSV export created by mongoexport, or potentially, another third-party export tool.

You have .json files. So, you can try mongoimport:

mongoimport --db <database_name> --collection <collection_name> <path to data.json>/data.json
like image 79
Dev Avatar answered Sep 24 '22 07:09

Dev