Deploying a ReplicaSet with one node fails (NotYetInitialized Error)

Hi folks! I am having trouble with the mongoDB tutorial to create replica sets. I want to create a replicaSet with a single node (don’t ask) and I am not sure what I am doing wrong so I thought I would post. Even when I tried with tutorial with 3 replicaSet nodes it failed. (I also had someone else follow my same steps and the error was the same on their end)

My goal here is to deploy a replica set with one node. (ie no replicas) According to [the mongodb documentation]( there are two tutorials that seem relevant [Deploy A Replica Set] and [Convert a Standalone to a Replica Set]. But after reading the purpose of “Convert a Standalone to a Replica Set” it seems that “Deploy A Replica Set” is more along the lines of what I need. (since I don’t already have an instance running)

Ubuntu: 20.04
MongoDB 5.0

First I create a new multipass instance so I have a clean machine

multipass launch -n replica-tutorial
multipass shell replica-tutorial

According to the documentation for Deploy A Replica Set I performed the following steps:


wget -qO - | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

I add my hostname to dns

sudo vim /etc/hosts

Note this ip is from the ip a command


sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 27017/tcp


sudo mkdir -p /data/db
sudo chown -R mongodb:mongodb /data/db
sudo chmod -R 777 /data/db

Add the following changes to the config file

sudo vi /etc/mongod.conf
  dbPath: /data/db

  replSetName: "rs0"

  bindIp: localhost,

[Start Member of Replica Set]

mongod --replSet "rs0" --bind_ip localhost, --dbpath /data/db

Note I add * --dbpath and the ip address listed here was retrieved from the command *ip a

At this point I get an error saying:

"NotYetInitialized: Replication has not yet been configured"

But initiation doesn’t happen until after [steps 2] and [3] in the tutorial so I am not sure why it can’t start until I initialize since according to the tutorial you are supposed to start the mongod instance and then initialize. What step am I missing

You have shown config file but started mongod from command line?

From where you are getting that message.How you are saying it did not start
You have to run rs.initiate() after connecting to the node to complete the setup

Hi @Ramachandra_Tummala thanks for responding to my post :slight_smile:

I got that message from the output of mongod --replSet "rs0" --bind_ip localhost, --dbpath /data/db

When I open a new shell and get access to the node with mongo ip and then do rs.initiate() it seems to get resolved. BUT mongod seems to keep running. After some googling I saw that mongod runs as a background process so it makes sense that it doesn’t terminate. Is it just some sort of logger?

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.