D
D
dufrein20132021-02-21 16:55:06
MongoDB
dufrein2013, 2021-02-21 16:55:06

How to convert mongo standalone to replica set?

I installed mongo on windows, or rather for use on WSL (ubuntu subsystem on Windows), I used it for pet project on JS, now I want to convert mongod to a replica set. How to do it on Windows?

I'll add
Sorry for the very basic questions
, the database is on Windows, through cmd I ran the command:

C:\Program Files\MongoDB\Server\4.2\bin>mongod --dbpath="C:\Program Files\MongoDB\Server\4.2\data" -bind_ip_all --replSet rs0
in response, the console displayed some information, and in the end this:

2021-03-01T02:28:09.459+0400 I CONTROL [LogicalSessionCacheReap] Failed to reap transaction table: NotYetInitialized: Replication has not yet been configured
2021-03-01T02:28:09.461+0400 I CONTROL [LogicalSessionCacheRefresh] Sessions collection is not set up; waiting until next sessions refresh interval: Replication has not yet been configured
after which, without waiting for the result, aborted the operation and entered mongo --eval 'rs.initiate();'
and that's it, this is the end of the operation, it turns out it was unsuccessful? How to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dufrein2013, 2021-03-01
@dufrein2013

I decided as follows, I explain for the same noobs like me.
Since I use Windows, albeit with wsl, the base lies at the Windows address and the commands will be appropriate.
1. first, in cmd, go to the address where the mongo.exe application lies, i.e. approximately here
C:\Program Files\MongoDB\Server\4.2\bin
2. Run the command
>mongod --port 27017 --dbpath="C:\Program Files\MongoDB\Server\4.2\data" --replSet rs0 -- bind_ip localhost
in response, the console displayed some information, after which
3. Run the mongo shell command utility and enter the command there
>rs.initiate ()
in response, some information will come out, you can say an object in JS style, there will be a field ok: 1, as I understood it means normal
4. You can enter the command check replica status info
> rs.status()

I
Ivan Shalganov, 2021-02-22
@Aco

I do not think that on WSL it will be different from the link. It is enough to restart mongod with the --replSet parameter:
/usr/bin/mongod -bind_ip_all --replSet rs0
After that, Standalone will turn into a replica from one node, then you can add replicas (don't forget about --replSet rs0) if necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question