Permalink
Browse files

Merge pull request #2 from ferrix/client

Authenticate to the database
  • Loading branch information...
2 parents 11810a9 + 1a60c89 commit 644fba72e385a749546d31275b485c19fb87af23 @fatiherikli committed Mar 7, 2013
Showing with 8 additions and 3 deletions.
  1. +8 −3 tastypie_mongodb/resources.py
@@ -1,5 +1,5 @@
from bson import ObjectId
-from pymongo import MongoClient
+from pymongo import MongoClient, Database
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
@@ -9,11 +9,16 @@
from tastypie.resources import Resource
-db = MongoClient(
+db = Database(MongoClient(
host=getattr(settings, "MONGODB_HOST", None),
port=getattr(settings, "MONGODB_PORT", None)
-)[settings.MONGODB_DATABASE]
+), settings.MONGODB_DATABASE])
+username = getattr(settings, "MONGODB_USERNAME", None)
+password = getattr(settings, "MONGODB_PASSWORD", None)
+
+if username and password:
+ db.authenticate(username, password)
class Document(dict):
# dictionary-like object for mongodb documents.

0 comments on commit 644fba7

Please sign in to comment.