安全插入的 Pymongo 权限问题 [英] Pymongo permissions issue for safe inserts

查看:48
本文介绍了安全插入的 Pymongo 权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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]).

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

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

推荐答案

您在 MongoDB 中以 auth 模式运行,并且没有在连接时提供相关的相关凭据.调用 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.

这篇关于安全插入的 Pymongo 权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆