I have an user(username:hxh,password:1234) in my local mongodb,when I execute :
hxh@ubuntu:~/share/nodejs/appid2zgk7rv83v$ mongo MongoDB shell version: 2.4.6 connecting to: test > use admin switched to db admin > db.auth('hxh','1234') 1 > This shows that my username and password is OK,but when I try to connect the mongodb in my nodejs app:
var Db = require('mongodb').Db; var Server = require('mongodb').Server; var db = new Db('test', new Server('localhost', '27017')); db.open(function(err, db) { db.authenticate('hxh', '1234', function(err, result) { ..... }); }); I got the error
MongoError: auth fails So why I got this error?