Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to mongodb with python

Tags:

python

mongodb

I tried connecting my application to my cluster on mongodb Atlas like the examples but I'm still having trouble.

I used

import pymongo
client = pymongo.MongoClient('mongodb+srv://kay:[email protected]/test')

I replaced myrealpassword with my password and cluster0 with my cluster's name .

This is the error i got :

Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/pymongo/mongo_client.py", line 468, in init res = uri_parser.parse_uri(entity, port, warn=True) File "/Library/Python/2.7/site-packages/pymongo/uri_parser.py", line 399, in parse_uri nodes = _get_dns_srv_hosts(fqdn) File "/Library/Python/2.7/site-packages/pymongo/uri_parser.py", line 289, in _get_dns_srv_hosts raise ConfigurationError(str(exc)) pymongo.errors.ConfigurationError: None of DNS query names exist: _mongodb._tcp.saudimood.mongodb.net., _mongodb._tcp.saudimood.mongodb.net.Home.

like image 369
Kacst Kacst Avatar asked Feb 07 '18 13:02

Kacst Kacst


1 Answers

I was having similar DNS error, I misspelled the DNS seed list :s

To avoid this and another errors try:

  1. In the Clusters view, click Connect for the cluster to which you want to connect.
  2. Select Connect your application.
  3. Select your driver and version.
  4. Copy the connection string.
  5. Replace <password> with the password for the <username> user. Replace myFirstDatabase with the name of the database that connections will use by default.

enter image description here

like image 191
Haniel Baez Avatar answered Sep 21 '22 13:09

Haniel Baez