LinuxCommandLibrary

mongoimport

imports data into MongoDB

TLDR

Import JSON file

$ mongoimport --db [dbname] --collection [coll] --file [data.json]
copy
Import CSV file
$ mongoimport --db [dbname] --collection [coll] --type csv --headerline --file [data.csv]
copy
Import with authentication
$ mongoimport -u [user] -p [pass] --db [dbname] --collection [coll] --file [data.json]
copy
Import from URI
$ mongoimport --uri "[mongodb://host/db]" --collection [coll] --file [data.json]
copy
Import with drop
$ mongoimport --db [dbname] --collection [coll] --drop --file [data.json]
copy
Import JSON array
$ mongoimport --db [dbname] --collection [coll] --jsonArray --file [array.json]
copy

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

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community