Sample Header Ad - 728x90

Not authorized on test to execute command

5 votes
1 answer
21437 views
Here is my code:
mongoose.connect(consts.database, {
	useNewUrlParser: true,
	useUnifiedTopology: true,
	sslCA: consts.databaseCert,
});
//...
const user = await db.userModel.findOne({
	username: usernameLowerCase
}).exec();
Here is my DB connection string (anonymized):
mongodb://myUser:userPW@SG-staging-111.servers.mongodirector.com:27017,SG-staging-43334.servers.mongodirector.com:27017?replicaSet=RS-staging-0&ssl=true&authSource=stagingDB
I'm getting this error:
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 user's info:
myUser	[{"role":"readWrite","db":"stagingDB"}]
I have no clue why I am getting this error not authorized on test to execute command, and in the return string $db: "test" I don't even have a database named test. What could I be doing wrong? I just recently added this new user myUser, but now I'm getting this error. Does this error mean that the user is not authorized to "test" commands? Or, does it mean that I am trying to (somehow) connect with a DB named "test"?
Asked by now_world (221 rep)
Feb 13, 2021, 07:31 AM
Last activity: Feb 9, 2023, 05:18 PM