mongoimport
imports data into MongoDB
TLDR
Import JSON file
$ mongoimport --db [dbname] --collection [coll] --file [data.json]
Import CSV file$ mongoimport --db [dbname] --collection [coll] --type csv --headerline --file [data.csv]
Import with authentication$ mongoimport -u [user] -p [pass] --db [dbname] --collection [coll] --file [data.json]
Import from URI$ mongoimport --uri "[mongodb://host/db]" --collection [coll] --file [data.json]
Import with drop$ mongoimport --db [dbname] --collection [coll] --drop --file [data.json]
Import JSON array$ mongoimport --db [dbname] --collection [coll] --jsonArray --file [array.json]
SYNOPSIS
mongoimport [options] [file]
DESCRIPTION
mongoimport imports data into MongoDB. It supports JSON, CSV, and TSV formats.
The tool bulk loads documents. Useful for data migration and seeding databases.
PARAMETERS
--db NAME
Database name.--collection NAME
Collection name.--file FILE
Input file path.--type TYPE
File type (json, csv, tsv).--headerline
Use first line as field names.--drop
Drop collection before import.--help
Display help information.
CAVEATS
Not for large datasets. Use mongorestore for BSON. May be slow on big imports.
HISTORY
mongoimport is part of MongoDB Database Tools, providing data import capabilities since MongoDB's early versions.
SEE ALSO
mongoexport(1), mongorestore(1), mongosh(1)
