EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MongoDB Tutorial MongoDB Import
Secondary Sidebar
MongoDB Tutorial
  • Advanced
    • MongoDB Array
    • PostgreSQL ARRAY_AGG()
    • Indexes in MongoDB
    • MongoDB create Index
    • MongoDB Collection
    • MongoDB List Collections
    • MongoDB Capped Collections
    • MongoDB Delete Collection
    • Mongodb show collections
    • MongoDB Auto Increment
    • MongoDB Triggers
    • MongoDB Projection
    • Replication in MongoDB
    • MongoDB Database
    • Mongo DB Create Database
    • MongoDB Compass
    • MongoDB Users
    • MongoDB Authentication
    • MongoDB GridFS
    • MongoDB Relationships
    • MongoDB MapReduce
    • MongoDB Geospatial
    • MongoDB Monitoring
    • Backup in MongoDB
    • MongoDB Sharding
    • MongoDB Java Drivers
    • MongoDB Import
    • Mongo Database Interview Questions
    • MongoDB Join Two Collections
    • MongoDB Group by Multiple Fields
    • MongoDB Pagination
    • MongoDB Replica Set
    • MongoDB Bulk Update
    • MongoDB greater than
    • MongoDB Encryption
    • MongoDB find in array
    • MongoDB like query
    • Mongodb shell
    • MongoDB port
    • MongoDB Query Operators
    • MongoDB Web Interface
    • MongoDB Query Array
    • MongoDB Transactions
    • MongoDB Not In
    • MongoDB not null
    • MongoDB npm
    • MongoDB Remove
  • Basics
    • What is MongoDB
    • How To Install MongoDB
    • MongoDB Tools
    • MongoDB GUI Tools
    • MongoDB Versions
    • MongoDB Commands
    • Advantages of MongoDB
    • MongoDB Features
    • Is MongoDB NoSQL
    • Is MongoDB Open Source
    • Build Web Applications using MongoDB
    • MongoDB Data Types
    • MongoDB Administration
    • Data Modeling in MongoDB
    • MongoDB vs Elasticsearch
    • MariaDB vs MongoDB
    • Firebase vs MongoDB
  • Commands
    • Mongodb updateMany
    • MongoDB Aggregation
    • Mongodb unwind
    • Mongodb where
    • MongoDB BSON
    • MongoDB Filter
    • Mongodb Match
    • MongoDB sort by date
    • MongoDB Limit()
    • MongoDB Atlas Login
    • MongoDB Relational Database
    • MongoDB count
    • MongoDB Aggregate
    • MongoDB Distinct
    • MongoDB Unique
    • MongoDB find
    • MongoDB findOne()
    • MongoDB insert
    • MongoDB Delete
    • MongoDB Update
    • Lookup in MongoDB
    • order by in MongoDB
    • MongoDB $regex
    • MongoDB $elemMatch
    • MongoDB ObjectId()
    • MongoDB Skip()
    • MongoDB findAndModify
    • Mongodb findOneAndUpdate
    • MongoDB Date Query
    • MongoDB Timestamp
    • MongoDB sort()
    • MongoDB group by
    • MongoDB Join

MongoDB Import

By Priya PedamkarPriya Pedamkar

MongoDB Import

Introduction to MongoDB Import

MongoDB Import command is used to import the document from the TSV, CSV or JSON file in MongoDB, mongoimport is the command line tool used for import the data from the file. MongoDB import is the part of the tool package in MongoDB, we can download this import package from the official download center.

Syntax of MongoDB Import

Below is the syntax of MongoDB Import.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Mongoimport --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:

  • Mongoimport: This command is used to load the data into collection by using the CSV, TSV and json files.
  • Uri: This is defined as connection URL which we have used while importing data from file in MongoDB.
  • User name: This is defined as username which we have used while importing data from the file.
  • User password: This is defined as password of user which we have used while importing data from the file.
  • Host name: This is defined as host name of database server which we have used while importing data from the file.
  • Port no: This is defined as port no. of database server which we have used while importing data from the file.
  • Database name: This is defined as name of database from which collection we are importing data from the file.
  • Collection name: This is defined as name of collection from which we are importing data from the file in MongoDB.
  • Authentication database: We need to define authentication database while importing data from the file.
  • File name: This parameter is defined as name of file from which we are importing data into the collection. We can import the data from CSV, TSV and JSON file in MongoDB.
  • Replica set name: While importing data from file we have to define replica set name while importing data into the collection.

How Import Command works in MongoDB?

We need to define database name, username, port number, password of user, and import file name at the time of importing data from file into the collection. We have used extended json format data to import data into the collection from json file. In newer version of MongoDB we have used extended json format data file to import document into the collection from the file.

We have used following options with mongoimport command in MongoDB at the time of 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

From MongoDB version 4.2 we have insert the document from the json file will be inserted in order which they will appeared into the file. Document will be sequentially insert into the collection as they will appeared from the input file. The bulk order insertion data is possible by using the mongoimport command in MongoDB. We have maintained insertion order flag to insert the documents as per the insertion order in MongoDB.

Examples

Given below are the examples of MongoDB Import:

Example #1

Import the data into the collection by using JSON file.

Below example shows that import the data into the collection by using JSON file. We have imported the data into import collection. We have used database name as admin at the time of insertion data into the import collection.

Code:

mongoimport --db admin --collection import --type json --file test.json
mongo
use admin
db.import.find()

Output:

MongoDB Import 1

Example #2

Import the data into the collection by using CSV file.

Below example shows that import the data into the collection by using CSV file. We have imported the data into import1 collection. We have used database name as admin at the time of insertion data into the import1 collection.

Code:

mongoimport --db admin --collection import1 --file test.csv
mongo
use admin
db.import1.find()

Output:

MongoDB Import 2

Example #3

Import the data into the collection by using TSV file.

Below example shows that import the data into the collection by using TSV file. We have imported the data into import2 collection. We have used database name as admin at the time of insertion data into the import2 collection.

Code:

mongoimport --db admin --collection import2 --file test.tsv
mongo
use admin
db.import2.find()

Output:

collection by using TSV file

Recommended Articles

This is a guide to MongoDB Import. Here we discuss the introduction, how import command works in MongoDB? and examples respectively. You may also have a look at the following articles to learn more –

  1. MongoDB Skip()
  2. MongoDB Auto Increment
  3. MongoDB Sharding
  4. MongoDB Features
Popular Course in this category
MongoDB Training Program (4 Courses, 2 Projects)
  4 Online Courses |  2 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle Training (17 Courses, 8+ Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
SQL Training Program (10 Courses, 8+ Projects)4.7
Oracle DBA Database Management System Training (2 Courses)4.7
MS SQL Training (16 Courses, 11+ Projects)4.7
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more