Permalink
Browse files

Patch adding authentication to MongoDb store, documentation pending

  • Loading branch information...
1 parent e6b67f1 commit 700126a2ac6f9053669d0e9b463ec5ca9e063280 @hannesgassert hannesgassert committed Jan 13, 2012
Showing with 23 additions and 9 deletions.
  1. +23 −9 lib/stores/mongodb.js
View
@@ -55,20 +55,34 @@ module.exports = function (options) {
callback(err, collection);
}
+ function collectionSetup() {
+ STORE.db.collection(options.collection || 'translations', function (err, collection) {
+ if (collection) {
+ connect(err, collection);
+ } else {
+ STORE.db.createCollection(options.collection || 'translations', function (err, collection) {
+ connect(err, collection);
+ });
+ }
+ });
+ }
+
if (!_is_connected) {
STORE.db.open(function (err, db) {
if (err) {
callback(err, null);
} else {
- STORE.db.collection(options.collection || 'translations', function (err, collection) {
- if (collection) {
- connect(err, collection);
- } else {
- STORE.db.createCollection(options.collection || 'translations', function (err, collection) {
- connect(err, collection);
- });
- }
- });
+ if (options.username && options.password) {
+ db.authenticate(options.username, options.password, function (err) {
+ if (err) {
+ callback(err, null);
+ } else {
+ collectionSetup();
+ }
+ });
+ } else {
+ collectionSetup();
+ }
}
});
}

0 comments on commit 700126a

Please sign in to comment.