0

我似乎无法defaultdict使用 PyMongo 向 MongoDB 写入数据。我得到了_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

4

0 回答 0