Pymongo 安全插入的权限问题

发布于 2024-10-29 23:58:48 字数 718 浏览 2 评论 0原文

我有一个正在运行的 Mongo 实例,可以成功连接数据库并进行身份验证。我可以使用collection.insert([要插入的记录列表])批量插入记录。

但是,当我添加 safe=True 以确保插入记录(如以下命令)时,我收到以下错误,这似乎是权限问题。我该如何解决这个问题?

    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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留蓝 2024-11-05 23:58:48

您正在 MongoDB 中以身份验证模式运行,并且在连接时未提供相关的相关凭据。调用 db.authenticate(...) 应该是你的朋友。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文