现在目前的情况是控制台和用工具连接都没有问题,但是mongoose查询数据时就会报未授权的错误。
- 代码如下:
const connect = ()=> {mongoose.connect('mongodb://username:password@127.0.0.1:27017/database');};
connect();
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
mongoose.connection.on('disconnected', connect);
- 然后试了这样子 还是不行
var options = {
db: { native_parser: true },
server: { poolSize: 5 },
replset: { rs_name: 'userAdmin' },
user: xxx
pass: xxx
}
const connect = ()=> {mongoose.connect('mongodb://xxx:xxx@127.0.0.1:27017/xxx',options)};
connect();
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
mongoose.connection.on('disconnected', connect);
var options = {
db: { native_parser: true },
server: { poolSize: 5 },
replset: { rs_name: 'userAdmin' },
user: xxx
pass: xxx
}
const connect = ()=> {mongoose.connect('mongodb://127.0.0.1:27017/xxx',options)};
connect();
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
mongoose.connection.on('disconnected', connect);
都不行,这个要怎么破?