Share & learn

Through Innovative Digital Library

What is mongoimport?

Explain about mongoimport? Why it is used? Explain with an example.
 



Answers

Posted by Nikheel on January 3rd 2018 14:34 PM

mongoimport : mongoimport is functionality provided by MongoDB to import JSON, CSV(Comma Separated Values), or TSV(Tab Separated values) files into a MongoDB database. Location of mongoimport : /mongodb/bin (path may vary according to installation) How to import? : Open a new Terminal and enter mongoimport followed by parameters like database name, collection name, source file name, etc. Let's try and import json file in MongoDB. Save this file as /home/nikheel/test.json {"address":[ {"building":"1007", "street":"Park Ave"}, {"building":"1008", "street":"New Ave"} ]} Use this command to import test.json file : Following image shows the result after using this command.

# mongoimport --db <db_name> --collection <coll_name> --type json --file file_name.json
 
e.g
#  mongoimport --db test --collection addresses --type json --file  /home/nikheel/test.json

Posted by Nikheel on January 3rd 2018 14:36 PM

Let's verify the import by connecting to the MongoDB database called test : Enter mongo shell by using following command > mongo Enter database name followed by 'use' : > use test Count the documents in the addresses collection with the command: > db.addresses.count() The result should show 1, exactly the number of the imported documents. We can also select the first document from the 'addresses' collection like this: > db.addresses.findOne()

Answer Question

Your email address will not be published. Required fields are marked *

  • Minimum 20 character
X3TH

related questions

Most liked questions

Most answered questions

Login
X3TH Refresh
Register
X3TH Refresh
Forgot password
Ask a Question
Minimum 20 character
Minimum 20 character
Reply
Minimum 20 character
X3TH Refresh