我使用pip安装了最新版本的Pymongo 3.2.2。另外我使用Python 3.4 Anaconda。我想做一个简单的插入。这是我的代码:
select case when mycolumn is null then 1 else 0 end
from mytable
这是我在Traceback底部得到的消息:
>>> 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)
如何修复此问题以便我可以将记录插入MongoDB?
答案 0 :(得分:4)
已在https://jira.mongodb.org/browse/PYTHON-1100中解决。问题是机器的hosts文件只有localhost映射到IPv6,默认情况下MongoDB不监听IPv6。