从python shell连接到mongodb的麻烦

时间:2015-10-08 01:04:32

标签: python mongodb

我正在使用python连接到mongodb。在mongodb一侧,我得到了连接,胸围立即终止。我是mongodb的新手。请建议我可能存在的问题。通过mongo shell我可以广告并检索条目,但我不能通过python shell做同样的事情。我正在运行版本db version v3.0.6

import pymongo
try:
    client = pymongo.MongoClient()
except pymongo.errors.OperationFailure as e:
    print e.code
    print e.details
db = client['test']
db.main.insert({'k':10})

输出e.code:

None

输出e.details:

local 2015-10-08 01:02:05.913000
isma True
maxMessage 48000000
o 1.0
maxBsonOb 16777216
minWire 0
maxWire 3
maxWriteB 1000

在mongod侧输出

2015-10-08T06:31:45.323+0530 I CONTROL  [initandlisten] db version v3.0.6
2015-10-08T06:31:45.323+0530 I CONTROL  [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f2
2015-10-08T06:31:45.323+0530 I CONTROL  [initandlisten] build info: Linux ip-10-67-194-123 2.6.32-220.el6.x86_64 #1 SMP Wed Nov 9 08:03:13 EST 2011 x86_64 BOOST_LIB_VERSION=1_49
2015-10-08T06:31:45.323+0530 I CONTROL  [initandlisten] allocator: tcmalloc
2015-10-08T06:31:45.323+0530 I CONTROL  [initandlisten] options: {}
2015-10-08T06:31:45.329+0530 I NETWORK  [initandlisten] waiting for connections on port 27017
2015-10-08T06:32:05.913+0530 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:55913 #1 (1 connection now open)
2015-10-08T06:32:05.914+0530 I NETWORK  [conn1] end connection 127.0.0.1:55913 (0 connections now open)

1 个答案:

答案 0 :(得分:0)

我认为应该是

client = pymongo.MongoClient("mongodb://localhost")