Load File with mongoimport
You can use mongoimport
to import data
from a JSON
or a CSV
file into MongoDB Atlas cluster.
Considerations
mongoimport
uses strict mode representation for certain BSON types.
Procedure
The following tutorial uses mongoimport
to
load data from a JSON
file to an Atlas cluster:
In Atlas, go to the Database Access page for your project.
If it's not already displayed, select the organization that contains your project from the Organizations menu in the navigation bar.
If it's not already displayed, select your project from the Projects menu in the navigation bar.
In the sidebar, click Database Access under the Security heading.
The Database Access page displays.
Set up a database user in the target Atlas cluster.
To run mongoimport
to write to Atlas cluster, you
must specify a database 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:
If it isn't already displayed, click the Database Users tab.
Click Add New Database User.
Add an Atlas admin user.
In Atlas, go to the Clusters page for your project.
If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it's not already displayed, select your desired project from the Projects menu in the navigation bar.
If it's not already displayed, click Clusters in the sidebar.
The Clusters page displays.
Update IP Access List.
If the host where you will run mongoimport
is not in the
IP Access List, update the list.
You can specify either:
The public IP address of the server on which
mongoimport
will run, orIf set up for VPC peering, either the peer's VPC CIDR block (or a subnet) or the peer VPC's Security Group, if you chose AWS as your cloud provider.
Copy the target cluster URI / host information.
You can connect to your Atlas cluster using its connection string URI. In the connect dialog box perform the following steps:
Click Drivers.
Copy the connection string found in step 1.
Replace PASSWORD with the password for the root user, and DATABASE with the name of the database to which you wish to connect.
Important
You must escape any instances of the
@
character in the provided<PASSWORD>
. For example,p@ssword
should bep%40ssword
.
This connection string is specified to mongoimport
in the
--uri
option.
When using --host
, if the Atlas cluster is a replica
set you must also retrieve the replica set name. For example:
myAtlasRS/atlas-host1:27017,atlas-host2:27017,atlas-host3:27017
Additional Information
For more information on mongoimport
, including behavior,
options, and examples, see the mongoimport reference page
.