Trying to create set but getting error

I am using mongodb 7.0.4 in parrotos.

I am using this code to create replica set

rs.initiate({
    _id: "rs1",
    members: [
        {_id: 0, host: "localhost:27018"},
        {_id: 1, host: "localhost:27019"},
        {_id: 2, host: "localhost:27020"}
    ]
});

but it is giving me error

MongoServerError: This node was not started with replication enabled.
    at Connection.onMessage (/usr/lib/mongodb-compass/resources/app.asar.unpacked/node_modules/@mongosh/node-runtime-worker-thread/dist/worker-runtime.js:2:840034)
    at MessageStream.<anonymous> (/usr/lib/mongodb-compass/resources/app.asar.unpacked/node_modules/@mongosh/node-runtime-worker-thread/dist/worker-runtime.js:2:837920)
    at MessageStream.emit (node:events:513:28)
    at p (/usr/lib/mongodb-compass/resources/app.asar.unpacked/node_modules/@mongosh/node-runtime-worker-thread/dist/worker-runtime.js:2:863891)
    at MessageStream._write (/usr/lib/mongodb-compass/resources/app.asar.unpacked/node_modules/@mongosh/node-runtime-worker-thread/dist/worker-runtime.js:2:862512)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)
    at Writable.write (node:internal/streams/writable:337:10)
    at Socket.ondata (node:internal/streams/readable:766:22)
    at Socket.emit (node:events:513:28)

what should I do?

Check replication parameter in your config files (all 3 nodes)

1 Like

opened this file /etc/mongod.conf

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
#  engine:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:

#operationProfiling:

#replication:

#sharding:
                     

nothing extra about all 3 nodes

Hi @Golu_Rajak

the problem is here:

from the documentation:

so you need to edit the configuration files of the various instances correctly.

Regards