Jonny Jonny - 1 year ago 100
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


app = Flask(__name__)
db = MongoEngine(app)

from .models import *

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

is a class within
that extends Document.

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

Upon calling
, 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 Source

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

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