Mongo : (Unauthorized) command insert requires authentication

Hi Team,

I have been trying to run my project on an AWS EC2 instance.
I have a Ubuntu instance, and on this, I tried using MongoDB as my database but as soon as I insert a document in it, it shows an error, not locally on my personal system but on this ubuntu.
Though it gets connected successfully.

I have used the official MongoDB driver.

“My connection string.”

clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")


    The error :(Unauthorized) command insert requires authentication
    2020/03/12 16:08:40 HTTP: panic serving runtime error: invalid memory 
    address or nil pointer dereference

Help me with this, please.

Hi, @vashish, I don’t have enough information to test this out myself to determine the cause of the error, but based on the “…nil pointer dereference” message below the “(Unauthorized) …” error, I suggest you check the code where you’re running the insert for any nil pointers.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.