I'm trying to use Mongolian in one of my projects and I'm using MongoHQ to host the databases however it requires a user/pass to access them. I couldn't find any docs on how to use authentication with Mongolian (it was hard to find any with mongo-node-native even). I开发者_运维百科s there a way to do this or will I have to fork mongolian and add this myself (I'd rather not since I'm very new to mongo and I don't really understand the mechanics of the driver)
I never used Mongolian but using the driver, when you connect to the database, you have to call db.authenticate
.
var db = new mongo.Db(dbname, new mongo.Server(host,port, options)),
collection = null,
getCollection = function (callback) {
db.collection(options.collection || defaults.collection, function (err, col) {
collection = col;
callback(null, col);
});
};
db.open(function () {
if (err) {
throw new Error("Error connecting to " + _url);
}
if (username && password) {
db.authenticate(username, password, function () {
getCollection(callback);
});
} else {
getCollection(callback);
}
});
精彩评论