Reputation: 365
I'm trying to get real-time updates from MongoDB. I used the changes stream API (from here). This is my code:
collection.watch().forEach(do_somthing);
But it just throws this error:
The $changeStream stage is only supported on replica sets
What is the meaning of replica sets
? How can I manage to fix this problem?
This is the first time I'm using MongoDB...
Thanks.
Upvotes: 0
Views: 2028
Reputation: 14865
For a simple local test you can run your mongodb like that
mongod --dbpath=d:\data --oplogSize 50 --replSet rs0
Upvotes: 0
Reputation: 3421
A replica set is a group of MongoDB processes that maintain the data set. Replica Sets replicate data by creating a special collection called the oplog which records all modifications to the data.
Change streams work by reading the oplog, so they require that your deployment are configured as a replica set.
See https://docs.mongodb.com/manual/tutorial/deploy-replica-set/ for a guide on deployment a replica set.
Upvotes: 1