这是我的代码:
mongoose.connect(consts.database, {
useNewUrlParser: true,
useUnifiedTopology: true,
sslCA: consts.databaseCert,
});
//...
const user = await db.userModel.findOne({
username: usernameLowerCase
}).exec();
这是我的数据库连接字符串(匿名):
mongodb://myUser:[email protected]:27017,SG-staging-43334.servers.mongodirector.com:27017?replicaSet=RS-staging-0&ssl=true&authSource=stagingDB
我收到此错误:
MongoError: not authorized on test to execute command {
find: "users",
filter: {
username: "bob"
},
projection: {},
limit: 1,
singleBatch: true,
batchSize: 1,
returnKey: false,
showRecordId: false,
lsid: {
id: UUID("0a9400e3-83e3-429c-b8c9-92ade2ff210e")
},
$clusterTime: {
clusterTime: Timestamp(1613200171, 1),
signature: {
hash: BinData(0, FED473B580D13E7E5073756DB5140981AADB2985),
keyId: 6928615819992774977
}
},
$db: "test"
}
DB用户信息:
myUser [{"role":"readWrite","db":"stagingDB"}]
我不知道为什么会收到此错误not authorized on test to execute command
,并且在返回字符串中$db: "test"
我什至没有名为test
. 我可能做错了什么?我最近刚刚添加了这个新用户myUser
,但现在我收到了这个错误。此错误是否意味着用户无权“测试”命令?或者,这是否意味着我正在尝试(以某种方式)连接名为“test”的数据库?