You are reading the article How Import Command Works In Mongodb? Examples updated in October 2023 on the website Vibergotobrazil.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested November 2023 How Import Command Works In Mongodb? Examples
Introduction to MongoDB ImportThe MongoDB Import command, known as mongoimport, is actively used to import documents from various file formats such as TSV, CSV, or JSON into MongoDB. The command line tool used for this purpose is called “mongoimport.” MongoDB import is part of the tool package in MongoDB; we can download this import package from the official download center.
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
Syntax of MongoDB ImportMongoimport --host (host name) -u (name of user) -p (password of user) --authenticationDatabase (admin database used for authentication) --db (Name of database) --collection (name of collection) --drop --file /name_of_file (Name of file which was we have used to import into collection)
Below is the parameter description syntax of MongoDB Import:
Uri: This is referred to as the “connection URL” that is used when importing data from a file into MongoDB.
User name: This is defined as the username which we have used while importing data from the file.
User password: This refers to the “user’s password” that is used during the process of importing data from a file in MongoDB.
Host name: This is defined as the hostname of the database server we have used while importing data from the file.
Port no: This is known as the “port number” of the database server, which is specified when importing data from a file into MongoDB.
Database name: This refers to the “name of the database” from which the collection’s data is imported from the file.
Collection name: This is the collection name from which we are importing data from the file in MongoDB.
Authentication database: We must define an authentication database while importing data from the file.
File name: This parameter is defined as the name of file from which we are importing data into the collection. We can import the data from CSV, TSV, and JSON files in MongoDB.
Replica set name: While importing data from file, we have to define the replica set name while importing data into the collection.
How Import Command works in MongoDB?We need to define the database name, username, port number, password of the user, and import file name at the time of importing data from the file into the collection. We have used extended json format data to import data into the collection from json files. In the newer version of MongoDB, we have used an extended json format data file to import documents into the collection from the file.
We have used the following options with mongoimport command in MongoDB when importing data into the collection.
Database name
Collection name
User name
User password
Host name
Port name
Authentication database
Replica set name
Authentication mechanism
File name
Drop keyword
Starting from MongoDB version 4.2, the insertion of documents from a JSON file follows the order in which they appear in the file. The bulk order insertion data is possible by using the mongoimport command in MongoDB. We have maintained an insertion order flag to insert the documents as per the insertion order in MongoDB.
ExamplesGiven below are the examples of MongoDB Import:
Example #1Import the data into the collection by using a JSON file.
The below example shows importing the data into the collection by using a JSON file. We have imported the data into the import collection. We have used the database name as admin at the time of insertion of data into the import collection.
Code:
Output:
Example #2Import the data into the collection by using a CSV file.
The below example shows importing the data into the collection by using a CSV file. We have imported the data into the import1 collection. We have used the database name as admin at the time of insertion of data into the import1 collection.
Code:
db.import1.find()
Output:
Example #3Import the data into the collection by using the TSV file.
The below example shows that importing the data into the collection by using a TSV file. We have imported the data into the import2 collection. We have used the database name as admin at the time of insertion of data into the import2 collection.
Code:
db.import2.find()
Output:
Recommended Articles
This is a guide to MongoDB Import. Here we discuss the introduction and how the import command works in MongoDB. and examples, respectively. You may also have a look at the following articles to learn more –
You're reading How Import Command Works In Mongodb? Examples
Update the detailed information about How Import Command Works In Mongodb? Examples on the Vibergotobrazil.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!