简体   繁体   中英

MongoDB Docker authentication problem “Error: Authentication failed”

I am trying to set up a MongoDB Docker container to use as a local database for testing, but I am facing issues.

For running the container, I used following command:

docker run -d --name mongodb -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME="root" -e MONGO_INITDB_ROOT_PASSWORD="password" -v C:\projects\docker\volumes\mongotmp:/data/db mongo:4.4.4

I used -e to pass the root username and password environment variables, but I am not able to connect to the database, I tried using this connection string:

mongodb://root:password@localhost:27017/?authSource=admin

When I execute a shell inside the container, and try to get the users with db.getUsers() I get an authentication error.

uncaught exception: Error: command usersInfo requires authentication :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.getUsers@src/mongo/shell/db.js:1659:15

Then, I tried authenticating with db.auth(root, password) , but no success.

uncaught exception: ReferenceError: root is not defined

As suggested in the comments, I had to put quotes around ("root", "password") for authorizing, but still no good.

Error: Authentication failed.

Someone online encountered this issue and the problem was that the person created and populated the volume before running the container with the environment variables, that way MongoDB wasn't able to find the root user. This shouldn't be the issue in my case because I removed the volume before spinning up the container.

This is a part of the container log:

{"t":{"$date":"2021-03-31T07:30:58.665+00:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"conn2","msg":"Slow query","attr":{"type":"command","ns":"admin.$cmd","appName":"MongoDB Shell","command":{"createUser":"root","pwd":"xxx","roles":[{"role":"root","db":"admin"}],"digestPassword":true,"writeConcern":{"w":"majority","wtimeout":600000.0},"lsid":{"id":{"$uuid":"d9cfc623-2db5-4798-bdfe-8fca9d9d5b76"}},"$db":"admin"},"numYields":0,"reslen":38,"locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":6}},"ReplicationStateTransition":{"acquireCount":{"w":6}},"Global":{"acquireCount":{"r":2,"w":4}},"Database":{"acquireCount":{"r":2,"W":4}},"Collection":{"acquireCount":{"r":1,"w":4}},"Mutex":{"acquireCount":{"r":6}}},"flowControl":{"acquireCount":4,"timeAcquiringMicros":5},"writeConcern":{"w":"majority","wtimeout":600000,"provenance":"clientSupplied"},"storage":{},"protocol":"op_msg","durationMillis":143}}

Successfully added user: {

"user" : "root",

"roles" : [

{

"role" : "root",

"db" : "admin"

}

]

}

Error saving history file: FileOpenFailed Unable to open() file /home/mongodb/.dbshell: No such file or directory

{"t":{"$date":"2021-03-31T07:30:58.669+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn2","msg":"Connection ended","attr":{"remote":"127.0.0.1:43118","connectionId":2,"connectionCount":0}}


/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/



{"t":{"$date":"2021-03-31T07:30:58.697+00:00"},"s":"I", "c":"CONTROL", "id":20698, "ctx":"main","msg":"***** SERVER RESTARTED *****"}

{"t":{"$date":"2021-03-31T07:30:58.700+00:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}

{"t":{"$date":"2021-03-31T07:30:58.702+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}

{"t":{"$date":"2021-03-31T07:30:58.702+00:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}

killing process with pid: 30

{"t":{"$date":"2021-03-31T07:30:58.705+00:00"},"s":"I", "c":"CONTROL", "id":23377, "ctx":"SignalHandler","msg":"Received signal","attr":{"signal":15,"error":"Terminated"}}

{"t":{"$date":"2021-03-31T07:30:58.705+00:00"},"s":"I", "c":"CONTROL", "id":23378, "ctx":"SignalHandler","msg":"Signal was sent by kill(2)","attr":{"pid":84,"uid":999}}

{"t":{"$date":"2021-03-31T07:30:58.705+00:00"},"s":"I", "c":"CONTROL", "id":23381, "ctx":"SignalHandler","msg":"will terminate after current cmd ends"}

{"t":{"$date":"2021-03-31T07:30:58.705+00:00"},"s":"I", "c":"REPL", "id":4784900, "ctx":"SignalHandler","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":10000}}

{"t":{"$date":"2021-03-31T07:30:58.706+00:00"},"s":"I", "c":"COMMAND", "id":4784901, "ctx":"SignalHandler","msg":"Shutting down the MirrorMaestro"}

{"t":{"$date":"2021-03-31T07:30:58.706+00:00"},"s":"I", "c":"SHARDING", "id":4784902, "ctx":"SignalHandler","msg":"Shutting down the WaitForMajorityService"}

{"t":{"$date":"2021-03-31T07:30:58.706+00:00"},"s":"I", "c":"CONTROL", "id":4784903, "ctx":"SignalHandler","msg":"Shutting down the LogicalSessionCache"}

{"t":{"$date":"2021-03-31T07:30:58.706+00:00"},"s":"I", "c":"NETWORK", "id":20562, "ctx":"SignalHandler","msg":"Shutdown: going to close listening sockets"}

{"t":{"$date":"2021-03-31T07:30:58.706+00:00"},"s":"I", "c":"NETWORK", "id":23017, "ctx":"listener","msg":"removing socket file","attr":{"path":"/tmp/mongodb-27017.sock"}}

{"t":{"$date":"2021-03-31T07:30:58.707+00:00"},"s":"I", "c":"NETWORK", "id":4784905, "ctx":"SignalHandler","msg":"Shutting down the global connection pool"}

{"t":{"$date":"2021-03-31T07:30:58.707+00:00"},"s":"I", "c":"STORAGE", "id":4784906, "ctx":"SignalHandler","msg":"Shutting down the FlowControlTicketholder"}

{"t":{"$date":"2021-03-31T07:30:58.707+00:00"},"s":"I", "c":"-", "id":20520, "ctx":"SignalHandler","msg":"Stopping further Flow Control ticket acquisitions."}

{"t":{"$date":"2021-03-31T07:30:58.707+00:00"},"s":"I", "c":"STORAGE", "id":4784908, "ctx":"SignalHandler","msg":"Shutting down the PeriodicThreadToAbortExpiredTransactions"}

{"t":{"$date":"2021-03-31T07:30:58.707+00:00"},"s":"I", "c":"STORAGE", "id":4784934, "ctx":"SignalHandler","msg":"Shutting down the PeriodicThreadToDecreaseSnapshotHistoryCachePressure"}

{"t":{"$date":"2021-03-31T07:30:58.707+00:00"},"s":"I", "c":"REPL", "id":4784909, "ctx":"SignalHandler","msg":"Shutting down the ReplicationCoordinator"}

{"t":{"$date":"2021-03-31T07:30:58.707+00:00"},"s":"I", "c":"SHARDING", "id":4784910, "ctx":"SignalHandler","msg":"Shutting down the ShardingInitializationMongoD"}

{"t":{"$date":"2021-03-31T07:30:58.707+00:00"},"s":"I", "c":"REPL", "id":4784911, "ctx":"SignalHandler","msg":"Enqueuing the ReplicationStateTransitionLock for shutdown"}

{"t":{"$date":"2021-03-31T07:30:58.707+00:00"},"s":"I", "c":"-", "id":4784912, "ctx":"SignalHandler","msg":"Killing all operations for shutdown"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"-", "id":4695300, "ctx":"SignalHandler","msg":"Interrupted all currently running operations","attr":{"opsKilled":3}}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"COMMAND", "id":4784913, "ctx":"SignalHandler","msg":"Shutting down all open transactions"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"REPL", "id":4784914, "ctx":"SignalHandler","msg":"Acquiring the ReplicationStateTransitionLock for shutdown"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"INDEX", "id":4784915, "ctx":"SignalHandler","msg":"Shutting down the IndexBuildsCoordinator"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"REPL", "id":4784916, "ctx":"SignalHandler","msg":"Reacquiring the ReplicationStateTransitionLock for shutdown"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"REPL", "id":4784917, "ctx":"SignalHandler","msg":"Attempting to mark clean shutdown"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"NETWORK", "id":4784918, "ctx":"SignalHandler","msg":"Shutting down the ReplicaSetMonitor"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"SHARDING", "id":4784921, "ctx":"SignalHandler","msg":"Shutting down the MigrationUtilExecutor"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"CONTROL", "id":4784925, "ctx":"SignalHandler","msg":"Shutting down free monitoring"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"CONTROL", "id":20609, "ctx":"SignalHandler","msg":"Shutting down free monitoring"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"STORAGE", "id":4784927, "ctx":"SignalHandler","msg":"Shutting down the HealthLog"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"STORAGE", "id":4784929, "ctx":"SignalHandler","msg":"Acquiring the global lock for shutdown"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"STORAGE", "id":4784930, "ctx":"SignalHandler","msg":"Shutting down the storage engine"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"STORAGE", "id":20282, "ctx":"SignalHandler","msg":"Deregistering all the collections"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"STORAGE", "id":22261, "ctx":"SignalHandler","msg":"Timestamp monitor shutting down"}

{"t":{"$date":"2021-03-31T07:30:58.708+00:00"},"s":"I", "c":"STORAGE", "id":22317, "ctx":"SignalHandler","msg":"WiredTigerKVEngine shutting down"}

{"t":{"$date":"2021-03-31T07:30:58.710+00:00"},"s":"I", "c":"STORAGE", "id":22318, "ctx":"SignalHandler","msg":"Shutting down session sweeper thread"}

{"t":{"$date":"2021-03-31T07:30:58.711+00:00"},"s":"I", "c":"STORAGE", "id":22319, "ctx":"SignalHandler","msg":"Finished shutting down session sweeper thread"}

{"t":{"$date":"2021-03-31T07:30:58.711+00:00"},"s":"I", "c":"STORAGE", "id":22320, "ctx":"SignalHandler","msg":"Shutting down journal flusher thread"}

{"t":{"$date":"2021-03-31T07:30:58.711+00:00"},"s":"I", "c":"STORAGE", "id":22321, "ctx":"SignalHandler","msg":"Finished shutting down journal flusher thread"}

{"t":{"$date":"2021-03-31T07:30:58.711+00:00"},"s":"I", "c":"STORAGE", "id":22322, "ctx":"SignalHandler","msg":"Shutting down checkpoint thread"}

{"t":{"$date":"2021-03-31T07:30:58.711+00:00"},"s":"I", "c":"STORAGE", "id":22323, "ctx":"SignalHandler","msg":"Finished shutting down checkpoint thread"}

{"t":{"$date":"2021-03-31T07:30:58.711+00:00"},"s":"I", "c":"STORAGE", "id":4795902, "ctx":"SignalHandler","msg":"Closing WiredTiger","attr":{"closeConfig":"leak_memory=true,"}}

{"t":{"$date":"2021-03-31T07:31:02.898+00:00"},"s":"E", "c":"STORAGE", "id":22435, "ctx":"thread1","msg":"WiredTiger error","attr":{"error":95,"message":"[1617175862:898369][30:0x7f2660703700], log-server: __posix_std_fallocate, 58: /data/db/journal/WiredTigerTmplog.0000000003: fallocate:: Operation not supported"}}

{"t":{"$date":"2021-03-31T07:31:02.898+00:00"},"s":"E", "c":"STORAGE", "id":22435, "ctx":"thread1","msg":"WiredTiger error","attr":{"error":95,"message":"[1617175862:898447][30:0x7f2660703700], log-server: __posix_sys_fallocate, 75: /data/db/journal/WiredTigerTmplog.0000000003: fallocate:: Operation not supported"}}

{"t":{"$date":"2021-03-31T07:31:07.244+00:00"},"s":"I", "c":"STORAGE", "id":4795901, "ctx":"SignalHandler","msg":"WiredTiger closed","attr":{"durationMillis":8533}}

{"t":{"$date":"2021-03-31T07:31:07.244+00:00"},"s":"I", "c":"STORAGE", "id":22279, "ctx":"SignalHandler","msg":"shutdown: removing fs lock..."}

{"t":{"$date":"2021-03-31T07:31:07.245+00:00"},"s":"I", "c":"-", "id":4784931, "ctx":"SignalHandler","msg":"Dropping the scope cache for shutdown"}

{"t":{"$date":"2021-03-31T07:31:07.245+00:00"},"s":"I", "c":"FTDC", "id":4784926, "ctx":"SignalHandler","msg":"Shutting down full-time data capture"}

{"t":{"$date":"2021-03-31T07:31:07.245+00:00"},"s":"I", "c":"FTDC", "id":20626, "ctx":"SignalHandler","msg":"Shutting down full-time diagnostic data capture"}

{"t":{"$date":"2021-03-31T07:31:07.256+00:00"},"s":"I", "c":"CONTROL", "id":20565, "ctx":"SignalHandler","msg":"Now exiting"}

{"t":{"$date":"2021-03-31T07:31:07.256+00:00"},"s":"I", "c":"CONTROL", "id":23138, "ctx":"SignalHandler","msg":"Shutting down","attr":{"exitCode":0}}


MongoDB init process complete; ready for start up.


{"t":{"$date":"2021-03-31T07:31:07.726+00:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}

{"t":{"$date":"2021-03-31T07:31:07.729+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}

{"t":{"$date":"2021-03-31T07:31:07.729+00:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}

{"t":{"$date":"2021-03-31T07:31:07.730+00:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"ca04a1bdd684"}}

{"t":{"$date":"2021-03-31T07:31:07.730+00:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.4","gitVersion":"8db30a63db1a9d84bdcad0c83369623f708e0397","openSSLVersion":"OpenSSL 1.1.1 11 Sep 2018","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"x86_64","target_arch":"x86_64"}}}}

{"t":{"$date":"2021-03-31T07:31:07.730+00:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"18.04"}}}

{"t":{"$date":"2021-03-31T07:31:07.730+00:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"*"},"security":{"authorization":"enabled"}}}}

{"t":{"$date":"2021-03-31T07:31:07.740+00:00"},"s":"I", "c":"STORAGE", "id":22270, "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"/data/db","storageEngine":"wiredTiger"}}

{"t":{"$date":"2021-03-31T07:31:07.746+00:00"},"s":"I", "c":"STORAGE", "id":22315, "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=4220M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}

{"t":{"$date":"2021-03-31T07:31:08.290+00:00"},"s":"E", "c":"STORAGE", "id":22435, "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":95,"message":"[1617175868:290197][1:0x7fc31420dac0], connection: __posix_std_fallocate, 58: /data/db/journal/WiredTigerTmplog.0000000001: fallocate:: Operation not supported"}}

{"t":{"$date":"2021-03-31T07:31:08.290+00:00"},"s":"E", "c":"STORAGE", "id":22435, "ctx":"initandlisten","msg":"WiredTiger error","attr":{"error":95,"message":"[1617175868:290294][1:0x7fc31420dac0], connection: __posix_sys_fallocate, 75: /data/db/journal/WiredTigerTmplog.0000000001: fallocate:: Operation not supported"}}

{"t":{"$date":"2021-03-31T07:31:12.592+00:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1617175872:592855][1:0x7fc31420dac0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 1 through 2"}}

{"t":{"$date":"2021-03-31T07:31:13.221+00:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1617175873:221071][1:0x7fc31420dac0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 2 through 2"}}

{"t":{"$date":"2021-03-31T07:31:13.841+00:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1617175873:841697][1:0x7fc31420dac0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Main recovery loop: starting at 1/29952 to 2/256"}}

{"t":{"$date":"2021-03-31T07:31:15.188+00:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1617175875:188227][1:0x7fc31420dac0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 1 through 2"}}

{"t":{"$date":"2021-03-31T07:31:16.064+00:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1617175876:64206][1:0x7fc31420dac0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 2 through 2"}}

{"t":{"$date":"2021-03-31T07:31:16.694+00:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1617175876:694002][1:0x7fc31420dac0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global recovery timestamp: (0, 0)"}}

{"t":{"$date":"2021-03-31T07:31:16.694+00:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1617175876:694073][1:0x7fc31420dac0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global oldest timestamp: (0, 0)"}}

{"t":{"$date":"2021-03-31T07:31:16.901+00:00"},"s":"I", "c":"STORAGE", "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":9155}}

{"t":{"$date":"2021-03-31T07:31:16.901+00:00"},"s":"I", "c":"RECOVERY", "id":23987, "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}

{"t":{"$date":"2021-03-31T07:31:16.903+00:00"},"s":"I", "c":"STORAGE", "id":4366408, "ctx":"initandlisten","msg":"No table logging settings modifications are required for existing WiredTiger tables","attr":{"loggingEnabled":true}}

{"t":{"$date":"2021-03-31T07:31:16.905+00:00"},"s":"I", "c":"STORAGE", "id":22262, "ctx":"initandlisten","msg":"Timestamp monitor starting"}

{"t":{"$date":"2021-03-31T07:31:16.909+00:00"},"s":"E", "c":"STORAGE", "id":22435, "ctx":"thread1","msg":"WiredTiger error","attr":{"error":95,"message":"[1617175876:909152][1:0x7fc30a503700], log-server: __posix_std_fallocate, 58: /data/db/journal/WiredTigerTmplog.0000000002: fallocate:: Operation not supported"}}

{"t":{"$date":"2021-03-31T07:31:16.909+00:00"},"s":"E", "c":"STORAGE", "id":22435, "ctx":"thread1","msg":"WiredTiger error","attr":{"error":95,"message":"[1617175876:909306][1:0x7fc30a503700], log-server: __posix_sys_fallocate, 75: /data/db/journal/WiredTigerTmplog.0000000002: fallocate:: Operation not supported"}}

{"t":{"$date":"2021-03-31T07:31:16.911+00:00"},"s":"W", "c":"CONTROL", "id":22178, "ctx":"initandlisten","msg":"/sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'","tags":["startupWarnings"]}

{"t":{"$date":"2021-03-31T07:31:16.918+00:00"},"s":"I", "c":"STORAGE", "id":20536, "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}

{"t":{"$date":"2021-03-31T07:31:16.921+00:00"},"s":"I", "c":"FTDC", "id":20625, "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"/data/db/diagnostic.data"}}

{"t":{"$date":"2021-03-31T07:31:16.924+00:00"},"s":"I", "c":"NETWORK", "id":23015, "ctx":"listener","msg":"Listening on","attr":{"address":"/tmp/mongodb-27017.sock"}}

{"t":{"$date":"2021-03-31T07:31:16.924+00:00"},"s":"I", "c":"NETWORK", "id":23015, "ctx":"listener","msg":"Listening on","attr":{"address":"0.0.0.0"}}

{"t":{"$date":"2021-03-31T07:31:16.924+00:00"},"s":"I", "c":"NETWORK", "id":23016, "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}

{"t":{"$date":"2021-03-31T07:31:21.738+00:00"},"s":"E", "c":"STORAGE", "id":22435, "ctx":"thread1","msg":"WiredTiger error","attr":{"error":95,"message":"[1617175881:738153][1:0x7fc30a503700], log-server: __posix_std_fallocate, 58: /data/db/journal/WiredTigerTmplog.0000000003: fallocate:: Operation not supported"}}

{"t":{"$date":"2021-03-31T07:31:21.738+00:00"},"s":"E", "c":"STORAGE", "id":22435, "ctx":"thread1","msg":"WiredTiger error","attr":{"error":95,"message":"[1617175881:738233][1:0x7fc30a503700], log-server: __posix_sys_fallocate, 75: /data/db/journal/WiredTigerTmplog.0000000003: fallocate:: Operation not supported"}}

{"t":{"$date":"2021-03-31T07:32:14.341+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:43120","connectionId":1,"connectionCount":1}}

{"t":{"$date":"2021-03-31T07:32:14.342+00:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn1","msg":"client metadata","attr":{"remote":"127.0.0.1:43120","client":"conn1","doc":{"application":{"name":"MongoDB Shell"},"driver":{"name":"MongoDB Internal Client","version":"4.4.4"},"os":{"type":"Linux","name":"Ubuntu","architecture":"x86_64","version":"18.04"}}}}

{"t":{"$date":"2021-03-31T07:32:33.098+00:00"},"s":"I", "c":"ACCESS", "id":20251, "ctx":"conn1","msg":"Supported SASL mechanisms requested for unknown user","attr":{"user":"root@test"}}

{"t":{"$date":"2021-03-31T07:32:33.099+00:00"},"s":"I", "c":"ACCESS", "id":20249, "ctx":"conn1","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","principalName":"root","authenticationDatabase":"test","client":"127.0.0.1:43120","result":"UserNotFound: Could not find user \"root\" for db \"test\""}}

In MongoDB, users are stored in databases but a database (or databases) that a user has access to doesn't need to be the same as the database in which that user is stored .

The database in which the user is stored is called the authentication database . This is configured via the authSource URI option and various language-specific driver options, as well as the --authenticationDatabase mongo shell option.

The error message says that you are authenticating against the test database. Your earlier shell command shows an attempt to authenticate against the admin database.

Review which database the user was created in and ensure that you use the same database during authentication.

The problem for me was that I forgot MongoDB was already running on my machine locally, so I had to map 27017 to a different port. Normally this would not work but somehow it didn't cause problems on startup, this prevented me from connecting with username and password.

I am using this command now:

docker run -d --name mongodb -p 8081:27017 -e MONGO_INITDB_ROOT_USERNAME="root" -e MONGO_INITDB_ROOT_PASSWORD="password" -v C:\projects\docker\volumes\mongotmp:/data/db mongo:4.4.4

With this connection string:

mongodb://root:password@localhost:8081/?authSource=admin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM