Permalink
Browse files

Merge branch 'master' of github.com:masylum/dialect

  • Loading branch information...
2 parents 606b475 + 971c032 commit 8303723c78b2114542c130aed71b4f05401b23a8 @masylum committed Jan 29, 2012
Showing with 31 additions and 10 deletions.
  1. +2 −0 Readme.md
  2. +28 −9 lib/stores/mongodb.js
  3. +1 −1 package.json
View
@@ -51,6 +51,8 @@ Dialect is a painless nodejs module to manage your translations.
* `host`: _127.0.0.1_
* `port`: _27017_
* `collection`: _translations_
+ * `username` (optional)
+ * `password` (optional)
* `sqlite`
* `database`: _dialect.db_
* `table`: _dialect_
View
@@ -55,20 +55,39 @@ module.exports = function (options) {
callback(err, collection);
}
+ function collectionSetup() {
+ STORE.db.collection(options.collection || 'translations', function (err, collection) {
+ if (collection) {
+ collection.ensureIndex(
+ {original: 1, locale: 1, translation: 1},
+ {unique: true},
+ function (err) {
+ 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();
+ }
}
});
}
View
@@ -4,7 +4,7 @@
"version": "1.0.3",
"author": "Pau Ramon <masylum@gmail.com>",
"dependencies": {
- "mongodb": "0.9.4",
+ "mongodb": "0.9.6-23",
"sqlite": "1.0.4",
"funk": "1.0.1"
},

0 comments on commit 8303723

Please sign in to comment.