Load File with mongoimport

You can use mongoimport to import data from a JSON or a CSV file into MongoDB Atlas cluster.


mongoimport uses strict mode representation for certain BSON types.


The following tutorial uses mongoimport to load data from a JSON file to an Atlas cluster:


Set up MongoDB user in the target Atlas cluster.

To run mongoimport to write to Atlas cluster, you must specify a MongoDB user that has readWrite privileges in the database into which to import data. For example, a user with Atlas admin role provides these privileges.

If no such user exists, create the user:

  1. Go to Clusters view, select the Security tab, and then Users.
  2. Click Add New User.
  3. Add an Atlas admin user.

Open the connect dialog.

From the Clusters view, click Connect for the Atlas cluster into which you want to migrate data.


Update IP Whitelist.

If the host where you will run mongoimport is not in the IP Whitelist, update the list. You can specify either:

  • The public IP address of the server on which mongoimport will run, or
  • If set up for VPC peering, either the peer’s VPC CIDR block (or a subnet) or the peer VPC’s Security Group.

Copy the target cluster host information.

From the connect dialog, get the cluster host information. This information is specified to mongoimport in the --host option.

If the Atlas cluster is a replica set, you must also retrieve the replica set name. For example:


Run mongoimport.

The following operation imports data from the file /somedir/myFileToImport.json into collection myData in the testdb database. The operation includes the --drop option to drop the collection first if the collection exists.

mongoimport --host myAtlasRS/atlas-host1:27017,atlas-host2:27017,atlas-host3:27017 --ssl -u myAtlasAdminUser -p 'atlasP@$$assw0Rd' --authenticationDatabase admin  \
   --db testdb --collection myData --drop --file /somedir/myFileToImport.json

Add/edit the mongoimport command line options as appropriate for your deployment. See mongoimport for more mongoimport options.

Additional Information

For more information on mongoimport, including behavior, options, and examples, see the mongoimport reference page.