Now after testing i found that these four instances are getting same data.
Hi Sanjeev,
By default, processes listening to the same change streams notification will receive the same data. In order to process the notifications without any duplication, you would need to handle this on the application/client side.
can anybody suggest me how to get the notification data in all the servers and no two servers will get the same data.
The answer would be depending on your environments and requirements. There are a few methods that you could try:
Create a worker pool, where you have only one instance listening to the Change Streams then delegate the task to one of the worker instances for processing.
Add an aggregation filter to each of the instances i.e. $match pipeline stage. For example, one instance is only going to handle notification where user has a specific id, etc.
Create a collection for locking. First instance able to insert a lock in a collection can process the notification.
Each of the methods above have their own pros and cons depending on your application use case.
Regards,
Wan.