Hi, I am a Windows user and I am using transactions with mongodb and I have to stop the mongodb service by:
net stop mongodb
and run as a replica set member like this:
mongod --replSet rs0 mongod is an alias for my file path to mongod.exe
I was just wondering whether there is a more efficient way to start mongodb service as a replica set member by default without being required to stop and run again because I use transactions quite offenly.
I tried to edit the mongod.cfg by adding the following lines which I found in the docs:
replication:
replSetName: rs0
but that did not work at all. When I edit this, I have to restart my PC because mongod also stops working after I edit this, and when I restart my PC, it gets fixed by itself.
Basically there is no issue in my current flow but I just want to make things more efficient. All I want to do is basically want to start the mongodb server as a replica set always so that I don’t have to net stop mongodb and mongod --replSet rs0 every time I turn my machine on!
You want to enable mongodb to run as a service when you install. Then the mongod.cfg in the install path will be used. If you did not do this you may be able to create your own with sc.exe.
Starting in version 4.0, you can install and configure MongoDB as a Windows Service during the install, and the MongoDB service is started upon successful installation. MongoDB is configured using the configuration file <install directory>\bin\mongod.cfg .
Sure. But if your mongod is not running as a service and/or referencing this configuration then no amount of changing this file is going to make a difference.
Get the configuration of the service with sc.exe qc MongoDB :
PS C:\Users\admin\Downloads> sc.exe qc MongoDB
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: MongoDB
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : "C:\Program Files\MongoDB\Server\4.4\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\4.4\bin\mongod.cfg" --service
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : MongoDB Server (MongoDB)
DEPENDENCIES :
SERVICE_START_NAME : NT AUTHORITY\NetworkService
This setting will not be conducive to a working replicaset as other members will not be able to connect.