Pymongo permissions issue for safe inserts

时光总嘲笑我的痴心妄想 提交于 2019-12-11 13:56:55

问题


I have an instance of Mongo running and can connect and authenticate successfully to a database. I can bulk insert records using collection.insert([list of records to insert]).

However, when I add safe=True to ensure that the records are inserted, like the following command, I get the error below, which seems like a permissions issue. How can I fix this?

    collection.insert(records_to_insert, safe=True)
  File "/.../python2.6/site-packages/pymongo/collection.py", line 270, in insert
    check_keys, safe, kwargs), safe)
  File "/.../python2.6/site-packages/pymongo/connection.py", line 732, in _send_message
    return self.__check_response_to_last_error(response)
  File "/.../lib/python2.6/site-packages/pymongo/connection.py", line 684, in __check_response_to_last_error
    raise OperationFailure(error["err"])
pymongo.errors.OperationFailure: unauthorized

回答1:


You are running in MongoDB in auth mode and did not provide the related the related credentials upon connection time. Calling db.authenticate(...) should be your friend.



来源:https://stackoverflow.com/questions/5532185/pymongo-permissions-issue-for-safe-inserts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!