How to Upload Json File in Mongodb
Import Data into MongoDB¶
Writer: MongoDB Documentation Team
In this guide, you lot volition employ the mongoimport tool distributed with MongoDB to bulk import data into your MongoDB instance.
Time required: fifteen minutes
Check Your Surround¶
You will need to ensure that your MongoDB instance is running and accessible.
Check that y'all have an Atlas account and take deployed a MongoDB database cluster. See Get Started with Atlas for information on how to login and create a cluster in Atlas.
- Windows
- macOS
- Linux
To make sure that your MongoDB case is running on Windows, run the following control from the Windows command prompt:
If a mongod.exe instance is running, you will run across something like:
To make certain your MongoDB instance is running on Mac, run the following command from your concluding:
If a mongod case is running, you volition encounter something like:
To brand sure your MongoDB instance is running on Linux, run the post-obit command from your concluding:
If a mongod instance is running, you will see something like:
Procedure¶
Download the sample data.¶
You volition be using a production inventory database for the Grime Getting Started guides. Download the inventory.grime.json file from GitHub.
Save the downloaded file to a file named inventory.grime.json in your downloads folder. If you wish to save the file somewhere else, yous can alter the value of the --file option to match your file's location and name.
Import the sample data into the inventory collection.¶
From your system vanquish or control prompt, utilise the mongoimport tool to insert the sample documents into the inventory collection in the test database. mongoimport is packaged with MongoDB and will be in the /bin directory of the MongoDB repository.
By default, mongoimport will import information into an instance of MongoDB on localhost , port 27017 . To import information into a MongoDB example running on a different host or port, specify the hostname or port by including the --host and --port options.
Use the --drop option to drop the collection if information technology already exists. This ensures that the collection will simply contain the data you are importing.
Tip
For non-Atlas instances, replace the <user> and <password> placeholders in the example with your MongoDB username and countersign. For all instances, update the --file path to point to wherever you lot accept saved your re-create of the product inventory database.
Go to cloud.mongodb.com to login to your user account.
In the cluster console, click the "…" push button as pictured below.
Select Control Line Tools from the menu.
Nether the Import and Consign Tools header, you will come across two copyable command line strings. Re-create the one for mongoimport .
You can use this control to run mongoimport by replacing the <DATABASE>, <PASSWORD>, <FILETYPE>, <COLLECTION> and <FILE> fields with the appropriate values.
In this case, <DATABASE> is test , <FILETYPE> is JSON , <FILE> is inventory.crud.json (preceded with qualified path), and <COLLECTION> is inventory .
mongoimport --db exam --collection inventory ^ --authenticationDatabase admin --username <user> --password <countersign> ^ --drop --file ~\downloads\inventory.grime.json
mongoimport --db test --drove inventory \ --authenticationDatabase admin --username <user> --countersign <countersign> \ --driblet --file ~/Downloads/inventory.crud.json
mongoimport --db test --drove inventory \ --authenticationDatabase admin --username <user> --password <countersign> \ --drib --file ~/Downloads/inventory.crud.json
Summary¶
If you accept successfully completed this guide, you have imported your first MongoDB data. In the next guide, yous will call up the documents that you just imported.
What's Next¶
In this guide, y'all volition think all of the documents in a collection in your MongoDB database.
- Read Information From MongoDB
Source: https://www.mongodb.com/docs/guides/server/import/
0 Response to "How to Upload Json File in Mongodb"
Post a Comment