Pymongo 安全插入的权限问题
我有一个正在运行的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在 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.