0

how to create replication in mongoDb (node js) in latest version.

i was trying mongodb documentation https://www.mongodb.com/docs/manual/tutorial/convert-standalone-to-replica-set/

i used this command to run instance as replication:

mongod --port 27017 --replSet rs0 --dbpath="C:\data\db0"

then in mongosh

run rs.initiate() command and getting error as replica set not found

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
Rustam Ansari
  • 117
  • 12
  • What kind of problem did you get? – Wernfried Domscheit Jan 06 '23 at 10:10
  • i was using command "rs.initiate()", again getting error "replica set not found" – Rustam Ansari Jan 06 '23 at 10:56
  • you should provide all information you have – dododo Jan 06 '23 at 11:21
  • Are you sure, you connected to the correct Mongo Database? Did you start multiple MongoDB instances on your machine? – Wernfried Domscheit Jan 06 '23 at 20:29
  • What is the output of the `mongod` command? – Wernfried Domscheit Jan 07 '23 at 22:10
  • @WernfriedDomscheit, i only have one mongoDB instance, i want create multiple instance using replica set, mongod command does not retunrs with any error. could you please let me know how can i run multiple instance. thanks – Rustam Ansari Jan 09 '23 at 12:50
  • "one mongoDB instance" and "using replica set" is contradicting (unless you use replica set with just one member, which is pointless). So again, what is the output of `mongod`? How do you start the other replica set members? Maybe have a look at https://github.com/Wernfried/mongoDB-oneclick – Wernfried Domscheit Jan 09 '23 at 15:38
  • When I am downloading MongoDB of the below 5.0 version, in mongo shell rs.initiate() command runs correctly. but when I am using MongoDB 6.0 rs.initiate() throwing error: This node is not running on replica set – Rustam Ansari Jan 10 '23 at 05:00

1 Answers1

1

Download mongosh new version and in mongo shell try to run these commands

rs.initiate();
rs.conf();