Jonny Jonny - 6 days ago 6
Python Question

Heroku mLab MongoDB admin user not authorized for query in Flask application

I have this section of code, which is part of my Flask application. I am using

flask_mongoengine
.

app = Flask(__name__)
app.config.from_object('config')
db = MongoEngine(app)

from .models import *


@app.context_processor
def inject_config():
return dict(Config.objects.first(), version=version)


Config
is a class within
.models
that extends Document.

class Config(Document):
title = StringField()
description = StringField()
keywords = StringField()
author = StringField()
version = StringField()
meta = {"collection": "web_config"}


Upon calling
Config.objects
, it's returning an error:

pymongo.errors.OperationFailure: database error: not authorized for query on heroku_dptwtq1j.web_config


I'm logged in through the admin user. Why am I not authorized for query? Also, how do I authorize myself to query?

I have no trouble querying through another application that uses PyMongo, so why is it not working in Flask?

Answer

So, answering my own question: the issue was probably in the flask_mongoengine library. I switched to just mongoengine and it worked fine.

Comments