向Mongo编写Python defaultdict失败

时间:2012-12-16 13:30:15

标签: python mongodb pymongo

我似乎无法使用PyMongo向MongoDB写一个defaultdict。我得到了_id,但文档没有写完。

>>> coll
Collection(Database(Connection('localhost', 27017), u'db_name'), u'coll_name')
>>> doc
{'field1': defaultdict(<type 'int'>, {...}), 'field2': defaultdict(<type 'int'>, {...})}
>>> obj_id = coll.insert(doc)
>>> obj_id
ObjectId('50cdc4df15b6f6dc3f496af7')
>>> coll.find_one()  # nothing...
>>> [x for x in coll.find({'_id': '50cdc4df15b6f6dc3f496af7'})]
[]

这里发生了什么?如何调试失败的写入?

修改

将我的连接切换到safe=True后,我明白了:

Traceback (most recent call last):
  File "populate_mongo.py", line 36, in <module>
    oid = coll.insert(series)
  File "/Users/user/.virtualenvs/test/lib/python2.7/site-packages/pymongo/collection.py", line 359, in insert
    continue_on_error, self.__uuid_subtype), safe)
  File "/Users/user/.virtualenvs/test/lib/python2.7/site-packages/pymongo/mongo_client.py", line 852, in _send_message
    rv = self.__check_response_to_last_error(response)
  File "/Users/user/.virtualenvs/test/lib/python2.7/site-packages/pymongo/mongo_client.py", line 795, in __check_response_to_last_error
    raise OperationFailure(details["err"], details["code"])
pymongo.errors.OperationFailure: too many namespaces/collections

所以这看起来像Mongo无法保存我的数据,并且与该集合无关defaultdict

0 个答案:

没有答案