0

I'm trying to use Flask-MongoKit as follows (with both attempts to find_one failing):

app = Flask('app-name')

db = MongoKit(app)

db.register([database.Users])

with app.app_context():
    print db['users'].find_one()
    print db.Users.find_one()

When I used plain MongoKit (non-Flask version), and this worked (as follows)

db = Connection()

db.register([database.Users])
print db.Users.find_one()

Thanks!

EDIT:

The database and collection are defined as follows.

class Users(Document):
    __collection__ = 'users'
    __database__ = 'database'
Jacob
  • 1,335
  • 1
  • 14
  • 28

1 Answers1

0

Flask-MongoKit doesn't use MongoKit's __database__ value. Instead, it uses an application config setting named MONGODB_DATABASE. If that isn't set, it defaults to a database named flask. If you change your code to

app = Flask('app-name')
app.config['MONGODB_DATABASE'] = 'database'
db = MongoKit(app)

your calls to find_one() should work.

The relative bits can be found here and here.

dirn
  • 19,454
  • 5
  • 69
  • 74