How to Install mongoimport on macOS M series

If you are using MongoDB on macOS M1 and need to import data into your database, you will require mongoimport, a command-line tool for importing JSON, CSV, or TSV data. This guide will walk you through installing mongoimport on macOS M1.

Step 1: Install MongoDB Database Tools

mongoimport is part of the MongoDB Database Tools package, which includes various utilities for managing and migrating data. The easiest way to install these tools on macOS M1 is through Homebrew.

Using Homebrew

To install the MongoDB Database Tools, open your terminal and run the following command:

brew install mongodb-database-tools

This command will install mongoimport along with other essential tools like mongodump and mongorestore.

Step 2: Verify the Installation

Once the installation is complete, check whether mongoimport has been installed correctly by running:

mongoimport --version

If installed successfully, you will see the version number of mongoimport displayed in the terminal.

Step 3: Alternative Manual Installation

If you prefer not to use Homebrew or run into issues, you can manually install the MongoDB Database Tools.

Manual Installation Steps

  1. Download the MongoDB Database Tools from the official MongoDB website:
    MongoDB Database Tools Download Page
  2. Select macOS as your operating system and download the appropriate package.

Verify the installation again by running:

mongoimport --version

Move the extracted binaries to a directory in your PATH, such as /usr/local/bin:

sudo mv mongodb-database-tools-*/bin/* /usr/local/bin/

Extract the downloaded file:

tar -xvf mongodb-database-tools-*.tar.gz

Step 4: Using mongoimport

Now that mongoimport is installed, you can use it to import data into MongoDB.

Example: Importing JSON Data

To import a JSON file (data.json) into a MongoDB database named myDatabase, run:

mongoimport --db myDatabase --collection myCollection --file data.json --jsonArray

Example: Importing CSV Data

To import a CSV file (data.csv) with headers:

mongoimport --db myDatabase --collection myCollection --type csv --file data.csv --headerline

Conclusion

Installing mongoimport on macOS M1 is simple using Homebrew or manual installation. Once installed, you can efficiently import data into your MongoDB database. If you encounter any issues, ensure that your MongoDB Database Tools path is correctly set. Happy coding!