javascript - Connecting to MongoDB over SSL with Node.js -
how connect mongodb-server on ssl using node.js?
i've read sources of few drivers (mongojs, mongodb-native) , i've been googling while now, can't seem find proper tutorials, guides or docs.
as suggested in comments, node-mongodb-native
has needed.
i got , running using following:
var mongo = require('mongodb'); var server = new mongo.server('hostname', 27017, { ssl: true }); var db = new mongo.db('name_of_my_db', server, { w: 1 }); var auth = { user: 'username', pass: 'password' }; db.open(function(err, db) { if (err) homecoming console.log("error opening", err); db.authenticate(auth.user, auth.pass, function(err, result) { if (err) homecoming console.log("error authenticating", err); console.log("authed?", result); db.collection('whatever').count(function(err, count) { if (err) homecoming console.log("error counting", err); console.log("count", count); db.close() }); }); });
edit
you can ssl mongoose:
mongoose.createconnection(connstring, { server: { ssl: true }})
javascript node.js mongodb ssl
No comments:
Post a Comment