1

I'm getting a KeyError 'errmsg' thrown while attempting to do a simple insert into a MongoDB collection. I've searched around and have not seen anything with this exact error ... where I believe the error message is not actually being populated by Pymongo.

It could be some syntax I'm overlooking, but I can do a .find_one() with no issue. It's just the .insert that's throwing. I believe Python 2.7.5 should be compatible with pymongo-2.7.

Any ideas? I'd appreciate any help!

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)

What's returning in the console:

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]

Note: The object that's returning with find_one() is just something I saved into the collection for the sake of testing and trying to figure out this issue.

mrg
  • 11
  • 2
  • Update: Using the collection object definition outlined here ( http://stackoverflow.com/questions/8783753/how-to-get-the-object-id-in-pymongo-after-an-insert) I was able to do the insert without issue. I'm still curious what's wrong with the method above since that seems to follow the Pymongo tutorial, unless, of course, it's just a stupid mistake by me. – mrg May 23 '14 at 16:28

0 Answers0