Kyras Kyras -4 years ago 208
Python Question

Cannot connect to mongodb usign mongoengine with read(only) access

I have working CLI tool created with mongoengine running on linux environment

MongoDB = 3.4.1
Python = 2.7.5
PyMongo = 3.4.0
MongoEngine = 0.11.0

I am connecting to database
with information in .ini file that looks like so:


In Python:

DB_CONN = mongoengine.connect(conf['dbname'], host=conf['uri'])

There are currently two users in database. User usrRO that have read role
and user usrRW that have readWrite role. When connecting to db using
user usrRW name and password in .ini file everything works.
But connecting with user usrRO credentials (user usrRO can read data from mongo CLI interface) leads to:

pymongo.errors.OpeartionFailure: not authorized on myapp to execute command
{ createIndexes: <collection_name>,
indexes: [ { unique: true,
backgroung: false,
sparse: false,
key: { name: 1 },
name: "name_1" } ],
writeConcern: {} }

Is there any way to use users usrRO credentials, or any other way to connect
to database with ready only privileges using mongoengine ?

Answer Source

I found the answer in the mongo-engine gitlab issues. Simply add

'auto_create_index': False

to your objects meta. This might not work for complex object structures.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download