I got three test servers using MongoDB 4 with cluster resultset. I stopped the primary node and MongoDB prompt on secondary node changed from 'rsExample:SECONDARY>' to '>'. Then, I started the primary node but MongoDB prompt on secondary node didn't change.

Is there any MongoDB command to restore the prompt from '>' to 'rsExample:SECONDARY>'?

  • How did you connect? If you connect properly to a Replica set (see Replica Set with Members on Different Machines) then a simple "ENTER" should restore your prompt. Jul 13, 2022 at 7:45
  • I connect by mongo -u "admin" -p --authenticationDatabase "admin" Jul 15, 2022 at 14:49
  • That's wrong, see linked documentation Jul 15, 2022 at 14:54
  • I don't think it's wrong to connect to mongoDB node. I think it's considered like other way. On the other side, I made testing according to your advice, but when I start the primary node again the prompt changes to '>' on secondary node. Therefore, it happens the same. The easy way is exiting the shell and logging again on secondary node. I don't see in MongoDB shell a command where the prompt '>' was refreshed. Jul 17, 2022 at 0:45

2 Answers 2


Yes... You need to "tell" the replica set that, that you want that first node to be primary whenever it's possible.

That is done by defining the 'priority' of the first node higher than other nodes. Here you can find how!

  • The priority nodes were established. Primary (node 1) Priority: 15, Secondary (node 2) Priority: 8 Secondary (Node 3) Priority: 1. Do you mean I have to change the priority on one of these nodes once Primary was stopped? If so, in which node? Jul 12, 2022 at 14:36
  • No need to change a priority. That node that has the highest priority AND has up-to-date content will be selected as PRIMARY. So, when node 1 "comes back", it will start at first as secondary, then update its content and when it has all changes replicated, it will come as PRIMARY again.
    – JJussi
    Jul 14, 2022 at 4:34

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 mongod process.

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.

mongo "mongodb://admin:password@host_1:27017,host_2:27017/?authSource=admin&replicaSet=repSet"

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.