nswbmw / koa-mongo

MongoDB middleware for koa, support connection pool.
145 stars 31 forks source link

about the auth #2

Closed zmofei closed 9 years ago

zmofei commented 9 years ago
  1. I add the user name and pwd
app.use(mongo({
    user: 'abc',
    pass: '123456',
}));

2.but when I use it , it return an error

this.mongo.db('zhuwenlong').collection('blog').findOne({}, function(err, doc) {
        console.log('xxxx', err, doc);
        //MongoError: not authorized for query on abc.blog
    })

why I have to auth again ? like this

this.mongo.authenticate("zhuwenlong", "123123",function(err,ret){
        this.mongo.db('zhuwenlong').collection('blog').findOne({}, function(err, doc) {
        console.log('xxxx', err, doc);
        //MongoError: not authorized for query on abc.blog
    })
})
nswbmw commented 9 years ago

try:

app.use(mongo({
    url: 'mongodb://abc:123456@localhost:27017'
}));
kylezhang commented 8 years ago

@zmofei The Q#2 is OK?

zmofei commented 8 years ago

@kylezhang ok