UserNotFound mongodb error I know there are lot of articles with the same issue and I explored every other article trying everything and still this error persists.
Here are the steps I followed:

use admin.

created an admin user with role: dbAdminAnyDatabase

use mydb.

created an admin user with different name for mydb

created a readonly user with: db.createUser({user: &quot;nameuser&quot;, pwd: &quot;password&quot;, roles: [{role: &quot;read&quot;, db: &quot;mydb&quot;}]});

setup a mongod.conf file with:

security:
authorization: enabled
net:
port: 12345
bindIp: 0.0.0.0   #default value is 127.0.0.1

then run the command: sudo mongod --port 27017 --dbpath ~/data/mongodb --config /etc/mongod.conf

and then on localhost i run the command to check:
mongo -u nameuser -p password localhost:12345/mydb

then the error come as:
connecting to: mongodb://localhost:12345/mydb MongoDB server version: 3.6.3 2020-10-04T03:05:37.054+0530 E QUERY    [thread1] Error: Authentication failed. : DB.prototype._authOrThrow@src/mongo/shell/db.js:1608:20 @(auth):6:1 @(auth):1:2 exception: login failed

and on server side the error looks like this:
2020-10-04T02:53:11.835+0530 I NETWORK  [listener] connection accepted from 127.0.0.1:60240 #3 (1 connection now open) 2020-10-04T02:53:11.835+0530 I NETWORK  [conn3] received client metadata from 127.0.0.1:60240 conn: { application: { name: &quot;MongoDB Shell&quot; }, driver: { name: &quot;MongoDB Internal Client&quot;, version: &quot;3.6.3&quot; }, os: { type: &quot;Linux&quot;, name: &quot;Ubuntu&quot;, architecture: &quot;x86_64&quot;, version: &quot;18.04&quot; } } 2020-10-04T02:53:11.836+0530 I ACCESS   [conn3] SCRAM-SHA-1 authentication failed for nameuser on mydb from client 127.0.0.1:60240 ; UserNotFound: Could not find user nameuser@mydb 2020-10-04T02:53:11.837+0530 I NETWORK  [conn3] end connection 127.0.0.1:60240 (0 connections now open)


Now please tell me if I can try anything new. I have tried so many articles from stackoverflow but none address the issue. Every resolved issue is the common mistake which I have checked already and I am not doing any of these. Tell me if you have any suggestion to work this out.
You need to use

--authenticationDatabase admin

parameter...  Because, even you give &quot;use mydb&quot; before creating user...  User is created at the admin -database.
So,
mongo -u nameuser -p password  --authenticationDatabase admin localhost:12345/mydb