db.adminCommand( { shutdown: 1 } ) error

I’ve bee following this tutorial to enable access control for MongoDB Community on my EC2 instance. Everything seems to go well until I run the db.adminCommand( { shutdown: 1 } ) from the instructions. I keep getting these error messages:

admin> db.adminCommand( { shutdown: 1 } )


MongoServerSelectionError: connect ECONNREFUSED

Caused by:

MongoNetworkError: connect ECONNREFUSED

Caused by:

Error: connect ECONNREFUSED

This leaves me really confused because I have to run this command inside the mongo shell, so how can the connection suddenly be broken? If I try to exit using Ctrl+C and use mongosh again, the same error appears: MongoNetworkError: connect ECONNREFUSED I can’t use mongosh with the new admin user I created either.

I’ve tried restarting the server over and over again, but the only thing that seems to work in running rm -f /tmp/mongodb-27017.sock, but only temporarily.

Well, when you shutdown the server, the server terminates. When a server is not running you cannot connect to it. Shutting down the server is really the last thing you can do with it. The situation might be a little bit different when you connect to a replica set as mongosh might stay connected to other members of the replica set.

However, I do not understand why you have to rm /tmp/…sock to keep going.