Pymongo投掷KeyError:'errmsg'

时间:2014-05-23 15:56:20

标签: python mongodb python-2.7 pymongo mongodb-query

我在尝试对MongoDB集合进行简单插入时遇到了KeyError'errmsg'。我已经四处搜索并且没有看到任何有这个确切错误...我相信错误信息实际上并没有被Pymongo填充。

这可能是我忽略的一些语法,但我可以做一个没有问题的.find_one()。这只是投掷的.insert。我相信Python 2.7.5应该与pymongo-2.7兼容。

有什么想法吗?我很感激任何帮助!

import twitter
import re
import pymongo
import sys

print (sys.version)

# spin up mongodb 
from pymongo import MongoClient 
client = MongoClient()
db = client.MLB_Replay
collection = db.MLB_Replay

print collection.find_one()

doc = {"name":"Michael","nickname":"mike"}

collection.insert(doc)

在控制台中返回了什么:

2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
{u'_id': ObjectId('537f5f7620190ca30570c846'), u'team': u'Rascals'}
Traceback (most recent call last):
  File "/Users/michael/Documents/Development/timeandtemp/mongotest.py", line 18, in <module>
    collection.insert(doc)
  File "/Library/Python/2.7/site-packages/pymongo-2.7-py2.7-macosx-10.9-intel.egg/pymongo/collection.py", line 402, in insert
  File "/Library/Python/2.7/site-packages/pymongo-2.7-py2.7-macosx-10.9-intel.egg/pymongo/mongo_client.py", line 1118, in _send_message
  File "/Library/Python/2.7/site-packages/pymongo-2.7-py2.7-macosx-10.9-intel.egg/pymongo/mongo_client.py", line 1034, in __check_response_to_last_error
  File "/Library/Python/2.7/site-packages/pymongo-2.7-py2.7-macosx-10.9-intel.egg/pymongo/helpers.py", line 151, in _check_command_response
KeyError: 'errmsg'
[Finished in 0.2s with exit code 1]

注意:使用find_one()返回的对象只是为了测试并试图找出此问题而保存到集合中的内容。

0 个答案:

没有答案