Not authorized on test to execute command 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&amp;ssl=true&amp;authSource=stagingDB

I'm getting this error:
MongoError: not authorized on test to execute command {
    find: &quot;users&quot;,
    filter: {
        username: &quot;bob&quot;
    },
    projection: {},
    limit: 1,
    singleBatch: true,
    batchSize: 1,
    returnKey: false,
    showRecordId: false,
    lsid: {
        id: UUID(&quot;0a9400e3-83e3-429c-b8c9-92ade2ff210e&quot;)
    },
    $clusterTime: {
        clusterTime: Timestamp(1613200171, 1),
        signature: {
            hash: BinData(0, FED473B580D13E7E5073756DB5140981AADB2985),
            keyId: 6928615819992774977
        }
    },
    $db: &quot;test&quot;
}


DB user's info:
myUser  [{&quot;role&quot;:&quot;readWrite&quot;,&quot;db&quot;:&quot;stagingDB&quot;}]

I have no clue why I am getting this error not authorized on test to execute command, and in the return string $db: &quot;test&quot; 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 &quot;test&quot; commands? Or, does it mean that I am trying to (somehow) connect with a DB named &quot;test&quot;?
Turns out that I was missing a /authDBName in my connection string. It should be this:
mongodb://myUser:userPW@SG-staging-111.servers.mongodirector.com:27017,SG-staging-43334.servers.mongodirector.com:27017/stagingDB?replicaSet=RS-staging-0&amp;ssl=true&amp;authSource=stagingDB