LinuxCommandLibrary

mongoimport

Imports content from a JSON, CSV, or TSV file into a MongoDB database.

TLDR

Import a JSON file into a specific collection

$ mongoimport --file=[path/to/file.json] --uri=[mongodb_uri] --collection=[collection_name]
copy


Import a CSV file, using the first line of the file to determine field names
$ mongoimport --type=[csv] --file=[path/to/file.csv] --db=[database_name] --collection=[collection_name]
copy


Import a JSON array, using each element as a separate document
$ mongoimport --jsonArray --file=[path/to/file.json]
copy


Import a JSON file using a specific mode and a query to match existing documents
$ mongoimport --file=[path/to/file.json] --mode=[delete|merge|upsert] --upsertFields="[field1,field2,...]"
copy


Import a CSV file, reading field names from a separate CSV file and ignoring fields with empty values
$ mongoimport --type=[csv] --file=[path/to/file.csv] --fieldFile=[path/to/field_file.csv] --ignoreBlanks
copy


Display help
$ mongoimport --help
copy

SYNOPSIS

mongoimport [options] [file]

DESCRIPTION

The mongoimport program allows loading data in CSV, TSV or JSON form into a running MongoDB instance.

OPTIONS

See mongoimport --help for a list supported options and their descriptions.

SEE ALSO

mongoexport(1) The full documentation of mongoimport can be found at https://docs.mongodb.com/manual/reference/program/mongoimport/.

AUTHOR

mongoimport was written by MongoDB, Inc. and is licensed under the Apache License, Version 2.0.

This manpage was written by Apollon Oikonomopoulos <apoikos@debian.org> for the Debian project (but may be used by others).

Copied to clipboard