How to load a CSV file to MongoDB Atlas?

This is the Atlas user interface that appears to me:


I cannot find here where to check the status.

I have Free Tier.

From these steps:

  1. Creating an Atlas Account.
  2. Deploy a Free Tier Cluster.
  3. Whitelist Your Connection IP Address.
  4. Create a MongoDB User for Your Cluster.
  5. Connect to Your Cluster.
  6. Insert and View Data in Your Cluster.

At first I took the first 4 steps, then, I jumped to step 6. I wanted to upload the data first, then to connect with an application.

Now, I tried to do the step 5, and could not perform it. I tried to connect from Google Colaboratory. At first it seemed ok, but when I tried to retrieve the collection names, I got this error:

ServerSelectionTimeoutError: connection closed,connection closed,connection closed, Timeout: 30s, Topology Description: <TopologyDescription id: 60c4a75ecb77fc969d50b269, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('cluster0-shard-00-00.acapz.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>, <ServerDescription ('cluster0-shard-00-01.acapz.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>, <ServerDescription ('cluster0-shard-00-02.acapz.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>]>

This is the python code I tried to use to connect with Atlas:

!pip install git+https://github.com/rthalley/dnspython
import pymongo
import dns

client = pymongo.MongoClient('mongodb+srv://tudor_15:Centurion15@cluster0.acapz.mongodb.net/myFirstDatabase?retryWrites=true&w=majority')

db = client['test']
col = db['test1']

#Till here, all is good 

print(db.list_collection_names()) #here I get the error
1 Like

FirstDatabase is a placeholder
Does it have any collections? i don’t think
That may be the reason list_collections is erroring

Coming back to your cluster status just click on clusters.You will see green icons and you will see a primary and two secondaries
Also at bottom of that page you will system status ok

Also click on database access.You should see the users created in database with privileges given to them

Can you connect to your database from shell?
From cmd prompt of Windows
try this
mongo “mongodb+srv://tudor_15:Centurion15@cluster0.acapz.mongodb.net/myFirstDatabase”

Have you whitelisted your IP? allow access for all

I created a database and a collection directly from Atlas:

Now I see the system status. It’s “All good”. :slight_smile:

Here is the user I use: tudor_15

I tried this but I got this error:
‘mongodb+srv:’ is not recognized as an internal or external command,
operable program or batch file.

I suppose an environment variable is needed. What do you think?
In any case, I have an environment variable set for MongoDB (local version).

Yes, I added my current IP address in “Network Access” tab.

I allowed access for all, but previously when I changed IP setting from my current IP to 0.0.0.0/0, this made no difference.

Have you tried the connect string exactly as i specified
Don’t think it is path problem

Most likely you forgot mongo at the beginning
Try again

Actually I tried the both options: with and without ‘mongo’. :smiley:

When put the ‘mongo’ in the beginning and I get this error:

*** You have failed to connect to a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.

Error: can't connect to new replica set master [cluster0-shard-00-01.acapz.mongodb.net:27017], err: AuthenticationFailed: bad auth : Authentication failed. :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1

bad auth means wrong combination of userid & password

I asked you to check database access tab in earlier post
Does tudor_15 exist in DB.Have you saved your password at the creation of this user?
Try to create another test user and see if you can login with that user

1 Like

I entered the ‘Database Access’ tab, and edited the ‘tudor_15’ user:

  • I edited the password to be ‘Centurion15’
  • I changed the type of user to be ‘admin’

After this, the command line that must perform the connection to Atlas worked. I seems that the previous password was not ‘Centurion15’. It’s strange, because with this password I connect to my cluster, through browser.

Now, this is what my command line looks like:

What to do next, to import the CSV files?

Good you were able to connect to your cluster from command line

Try your mongoimport command which you tried before
Make sure you are in the directory where your invoice_train.csv file is residing

I tried to run this command line:

mongoimport --uri mongodb+srv://tudor_15:Centurion15@cluster0.acapz.mongodb.net/Database1 --collection Invoice_Train --type CSV --file client_test.csv --headerline

And I got this error:

2021-06-13T19:44:07.106+0300 error parsing command line options: error parsing uri: lookup _mongodb._tcp.cluster0.acapz.mongodb.net: dnsquery: This operation returned because the timeout period expired.
2021-06-13T19:44:07.116+0300 try 'mongoimport --help' for more information

Looks like your ISP not supporting SRV or blocking it
Try long form of connect string or change to google DNS 8.8.8.8 and see if it works
Search our forum for long form string & DNS settings

Finally, I could upload the data in Atlas, by changing the DNS settings, with the help of this post:

Thank you very much for your help!

how to the next import file csv?

What data you want to import to your cluster?
You can get exact command from your Atlas command line tools

I want to file data.csv? but I can’t import it? Can you help me? ex

What to do next, to import the CSV files?


You can see the picture. I want to import the file database.csv in MongoDB Atlast but I can’t import it?

What command you used and what error are you getting?
First check whether you can connect to your cluster from command line
Then use
mongoimport --uri your_onnect_string
Pass other parameters like dbname collection name etc

1 Like

I open cmd :



The first i use command :
mongo “mongodb+srv://admin:@cluster0.d3ri6.mongodb.net/”
then appear in the píc

and the next i use command
mongoimport --uri mongodb+srv://admin:n@cluster0.d3ri6.mongodb.net/iot --collection iot_data --type csv --file ~C:/Program Files/MongoDB/Server/5.0/bin/database.csv~

I can’t import it?

You are running it at mongoprompt
Please exit and run from os prompt

1 Like

Can you help me with a video on how to do it?