Accept non-url format in mongoose adapter

This commit is contained in:
Anatoliy Chakkaev 2011-11-05 17:16:34 +07:00
parent 9f9aa7cd3f
commit 683833b220
2 changed files with 25 additions and 1 deletions

View File

@ -4,6 +4,27 @@
var mongoose = require('mongoose');
exports.initialize = function initializeSchema(schema, callback) {
if (!schema.settings.url) {
var url = schema.settings.host || 'localhost';
if (schema.settings.port) url += ':' + schema.settings.port;
var auth = '';
if (schema.settings.username) {
auth = schema.settings.username;
if (schema.settings.password) {
auth += ':' + schema.settings.password;
}
}
if (auth) {
url = auth + '@' + url;
}
if (schema.settings.database) {
url += '/' + schema.settings.database;
} else {
url += '/';
}
url = 'mongodb://' + url;
schema.settings.url = url;
}
schema.client = mongoose.connect(schema.settings.url);
schema.adapter = new MongooseAdapter(schema.client);
callback();

View File

@ -16,7 +16,10 @@ var schemas = {
username: 'root'
},
neo4j: { url: 'http://localhost:7474/' },
mongoose: { url: 'mongodb://localhost/test' },
// mongoose: { url: 'mongodb://localhost/test' },
mongoose: {
database: 'test'
},
redis: {},
memory: {}
};