Skip to content

Instantly share code, notes, and snippets.

@nikhilkumarsingh
Created April 7, 2019 16:45
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save nikhilkumarsingh/2c39d161f3d5fe4a40c24d7c9a7a11c3 to your computer and use it in GitHub Desktop.
Save nikhilkumarsingh/2c39d161f3d5fe4a40c24d7c9a7a11c3 to your computer and use it in GitHub Desktop.
Working with mongoDB Atlas using Python
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@soumilshah1995
Copy link

Gives Error

from pymongo import MongoClient
client = MongoClient("xxxxxx")
db = client.get_database('student_db')
records = db.student_record

new_student = {

'name': 'ram'

}

records.insert_one(new_student)

Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/soumilshah/IdeaProjects/Mongo/aaa.py", line 2, in
client = MongoClient("mongodb+srv://admin:admin@cluster0-ooywi.mongodb.net/test?retryWrites=true")
File "/Users/soumilshah/Library/Python/3.7/lib/python/site-packages/pymongo/mongo_client.py", line 494, in init
res = uri_parser.parse_uri(entity, port, warn=True)
File "/Users/soumilshah/Library/Python/3.7/lib/python/site-packages/pymongo/uri_parser.py", line 399, in parse_uri
nodes = _get_dns_srv_hosts(fqdn)
File "/Users/soumilshah/Library/Python/3.7/lib/python/site-packages/pymongo/uri_parser.py", line 289, in _get_dns_srv_hosts
raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: The DNS operation timed out after 30.00140118598938 seconds

Process finished with exit code 1

@sthamamta
Copy link


NameError Traceback (most recent call last)
in
----> 1 records.insert_one(new_student)

NameError: name 'new_student' is not defined

I ran to into this error. How can i fix this?.Thank you in advance

@NgoziOkereke
Copy link

@sthamamta Hi, I do not know if you are still looking for a solution. I think you have that error because of the variable name. You probably named your dict "new_students", then you are trying to add "new_student" which is missing an s.

@harisn5181
Copy link

can you provide me a useful resouces for cloud atlas.most of the resouces which i get is only for mongodb ..that is not working for mongodb cloud atlas

@Akash0973
Copy link

I am getting this error while connecting-

"
ServerSelectionTimeoutError: ac-myscqgc-shard-00-02.wnjhomu.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992),ac-myscqgc-shard-00-00.wnjhomu.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992),ac-myscqgc-shard-00-01.wnjhomu.mongodb.net:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 6515872d8f3f9b1363275592, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('ac-myscqgc-shard-00-00.wnjhomu.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-myscqgc-shard-00-00.wnjhomu.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)')>, <ServerDescription ('ac-myscqgc-shard-00-01.wnjhomu.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('ac-myscqgc-shard-00-01.wnjhomu.mongodb.net:27017: timed out')>, <ServerDescription ('ac-myscqgc-shard-00-02.wnjhomu.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-myscqgc-shard-00-02.wnjhomu.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)')>]>
"

How to resolve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment