Accept non-url format in mongoose adapter
This commit is contained in:
parent
9f9aa7cd3f
commit
683833b220
|
@ -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();
|
||||
|
|
|
@ -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: {}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue