Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Authenticating to database

I'm not sure, but it looks like we need to authenticate before accessing a database on remote mongod.
Maybe that's a new feature of pymongo/mongokit ?

Warning: code wasn't tested to exhaustion.
  • Loading branch information...
commit 6b8b11f7648c3fd0d9f4343c3f9dfb836f56cde8 1 parent cc15faf
@caruccio authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 django_mongokit/shortcut.py
View
9 django_mongokit/shortcut.py
@@ -45,9 +45,14 @@
# differently as long as you use get_database()
def get_database(this_connection=connection):
if __django_12__:
- return this_connection[settings.DATABASES['mongodb']['NAME']]
+ db = this_connection[settings.DATABASES['mongodb']['NAME']]
else:
- return this_connection[settings.MONGO_DATABASE_NAME]
+ db = this_connection[settings.MONGO_DATABASE_NAME]
+ try:
+ db.authenticate(settings.DATABASES['mongodb'].get('USER', ''), settings.DATABASES['mongodb'].get('PASSWORD', ''))
+ except AttributeError:
+ pass
+ return db
def get_version():
Please sign in to comment.
Something went wrong with that request. Please try again.