[英]Read-only mode for a pymongo.MongoClient connection to MongoDB
For a project , I'm currently running a local MongoDB instance without authentication. 对于一个项目 ,我目前正在运行一个没有身份验证的本地MongoDB实例。
I connect to the database in python using pymongo. 我使用pymongo连接到python中的数据库。 For most use cases, I'll only want to run read queries.
对于大多数用例,我只想运行读取查询。 I'd like to specify a read-only
pymongo.MongoClient
connection, so I can avoid accidental write operations, which could mess up the database. 我想指定一个只读的
pymongo.MongoClient
连接,这样我就可以避免意外的写操作,这可能会弄乱数据库。
There is an existing related question that is in the context of replicas. 在副本的背景下存在一个现有的相关问题 。 In my case, there is a single node running in Docker.
就我而言,Docker中有一个节点在运行。 I also looked through the read preference docs .
我还查看了阅读偏好文档 。
The only way to prevent accidentally modifying your MongoDB data is by enabling authentication. 防止意外修改MongoDB数据的唯一方法是启用身份验证。 PyMongo and other drivers do not have a feature that can accomplish this goal.
PyMongo和其他驱动程序没有可以实现此目标的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.