I installed the latest version of Pymongo 3.2.2 using pip. Additionally I use Python 3.4 Anaconda. I am trying to do a simple insert. Here is my code:
>>> from pymongo import MongoClient
>>> client = MongoClient(connect=False)
>>> client["mydb"]
Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'mydb')
>>> db = client["mydb"]
>>> collection = db["mycollection"]
Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'mydb'), 'mycollection')
>>> book = {}
>>> book["title"] = "AnyBook"
>>> book["Author"] = "AnyAuthor"
>>> collection.insert(book)
This is the message I get at the bottom of the Traceback:
Traceback (most recent call last):
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 8] nodename nor servname provided, or not known
How can I fix this so that I can insert a record into MongoDB?
Resolved in https://jira.mongodb.org/browse/PYTHON-1100. The issue was the machine's hosts file had localhost mapped only to IPv6 and MongoDB doesn't listen on IPv6 by default.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments