Hi @Kevin_Meng,
Can you try adding authentication information into the URI itself:
clientOptions := options.Client.ApplyURI("mongodb://USERNAME:PASSWORD@127.0.0.1:32768/"
client, err := mongo.Connect(ctx, clientOptions)
Doing it this way will allow the driver to automatically authenticate each connection that it creates to the MongoDB deployment. You will not need to manually run the authenticate command.
If I’m misunderstanding your use case and this solution doesn’t address your question, can you provide some information about why you need to manually execute this command?
– Divjot