Hello
I’m working on a realtime application with mongodb, socket .io ,node. For this , someone suggested me to use change to get realtime changes in the database .
I’m using mongoose and i tried
const db = mongoose.connection
db.once("open", () => {
const collection = db.collection("posts")
const changeStream = collection.watch()
changeStream.on('change', next => {
console.log("working")
});
It throws me error like
MongoServerError: The $changeStream stage is only supported on replica sets, docker
I trield and found , In order to use replica set , while running mongodb we have to pass " --replSet
"
mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0 --bind_ip localhost,<hostname(s)|ip address(es)>
Here i’m using docker on gnu/linux. I’ve setup all everything through official docker.
Docker automatically starts on container id “e5cf38616459” , on running command
docker start e5cf38616459
and database will be connected .
But i’m thinking
Where should i put --replSet
?
Is there any script that runs when docker start, if so where can i put that script automatically when docker start. Or if is there any configuration file can i change to include the --replSet , It would be very helpful.
Thank you for your help.