2

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?

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.