Forrest logo
tool overview
On this page you find all important commands for the CLI tool mongoimport. If the command you are looking for is missing please ask our AI.

mongoimport

Mongoimport is a command-line tool provided by MongoDB for importing data from various file formats into MongoDB databases. Using mongoimport, you can efficiently insert large amounts of data into your MongoDB collections from JSON, CSV, TSV, or BSON files.

This tool offers several options to customize the import process, such as specifying the database and collection to import the data into, defining the file format, and mapping fields in the input file to fields in the MongoDB document. Additionally, you can control the behavior when encountering duplicate entries or errors during the import.

Mongoimport provides support for importing data from remote databases through the use of the --uri option or by specifying connection details directly in the command. It also supports authentication mechanisms like username/password and authentication databases.

You can use mongoimport to import data into both standalone MongoDB instances and replica sets. In the replica set scenario, mongoimport automatically redirects the import operation to the primary node to ensure data consistency.

This tool is particularly useful for initial data import, batch updates, or data migration tasks in MongoDB. It offers a straightforward and scalable way to load large datasets into your MongoDB collections efficiently.

Mongoimport is part of the MongoDB database server installation and can be accessed through the command prompt or terminal. It is among the efficient and commonly used tools within the MongoDB ecosystem for managing data import operations.

List of commands for mongoimport:

  • mongoimport:help mongoimport: Display help.
    $ mongoimport --help
    try on your machine
    explain this command
  • mongoimport:tldr:596dd mongoimport: Import a JSON file using a specific mode and a query to match existing documents.
    $ mongoimport --file=${filename-json} --mode=${select} --upsertFields="${field1,field2,---}"
    try on your machine
    explain this command
  • mongoimport:tldr:996b7 mongoimport: Import a CSV file, using the first line of the file to determine field names.
    $ mongoimport --type=${csv} --file=${filename-csv} --db=${database_name} --collection=${collection_name}
    try on your machine
    explain this command
  • mongoimport:tldr:ba410 mongoimport: Import a JSON file into a specific collection.
    $ mongoimport --file=${filename-json} --uri=${mongodb_uri} --collection=${collection_name}
    try on your machine
    explain this command
  • mongoimport:tldr:c3fb2 mongoimport: Import a CSV file, reading field names from a separate CSV file and ignoring fields with empty values.
    $ mongoimport --type=${csv} --file=${filename-csv} --fieldFile=${path-to-field_file-csv} --ignoreBlanks
    try on your machine
    explain this command
  • mongoimport:tldr:e371f mongoimport: Import a JSON array, using each element as a separate document.
    $ mongoimport --jsonArray --file=${filename-json}
    try on your machine
    explain this command
tool overview