Search This Blog

Friday, July 24, 2020

Import Data into MongoDB


Import Data into MongoDB: ------------

To make sure your MongoDB instance is running on Linux, run the following command from your terminal:

ps -e| grep 'mongod'

If a mongod instance is running, you will see something like:

89780 ttys026    0:53.48 ./mongod


Import the sample data into the inventory collection.

From your system shell or command prompt, use 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 data into an instance of MongoDB on localhost, port 27017. To import data into a MongoDB instance 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 it already exists. This ensures that the collection will only 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 password. For all instances, update the --file path to point to wherever you have saved your copy of the product inventory database.

mongoimport --db test --collection inventory \
          --authenticationDatabase admin --username <user> --password <password> \
          --drop --file ~/Downloads/inventory.crud.json

No comments:

Post a Comment