Seems to be difficult. When you connect to a single node with
mongo -u "admin" -p --authenticationDatabase "admin" and the
mongod service on this node stops, then the connection is lost, i.e. the default prompt changes to
>. This state remains even if you restart the
You have to exit the shell and reconnect or use the Mongo() command.
Even a redefinition of
prompt variable does not work.
However, the new mongo shell
mongosh performs a reconnect automatically and restores the prompt.
Anyway, the best way would be to connect to the replica set, rather than to a single node, e.g.
then the connection remains active or reconnect automatically even is you stop the PRIMARY. If you want to read data from SECONDARY for whatever reason then better use the Read Preference