Do i need to do db.logout() before changing another db password in mongoDB

47 Views Asked by At

consider i have two database in mongoDB say db1 and db2 i want to change the password for both initially , do i need to logout db1 before changing db2 password ? or that is not required ? what's the best practice?

current sequence

conn, err := mongo.connect(ctx, connOpts)

//then update the db pass
cmd := bson.D{{"updateUser", dbUserName}, {"pwd", newPass}}
err = client.Database(db1).RunCommand(context.TODO(), command, opts).Decode(&result)

//then logout
err = client.Database(db1).RunCommand(context.TODO(), bson.D{{"logout", 1}}, opts).Decode(&result)


//repeat the same steps again for changing the db2 password

Am I following the right sequence ? whether connecting the db once is enough to do both operation ? is login and logout really required here ?

I'm using go mongo driver .

0

There are 0 best solutions below