Reputation: 1694
I am using MongoDB 4.0 as 3 nodes replica-set. 2 data nodes and 1 arbiter. My application (ASP.NET Core 2.2) uses change stream. Consider this scenario, my primary node goes down, my secondary node becomes primary and I replace in my replica-set the node that is down with a new node and it starts to be synced. What will happen to my change stream in this case?
And my second question is, in my application, readPreference
is secondary
and when my secondary node goes down I expect MongoDB to automatically read from primary
but it didn't happen and my application had issue in read. Is it normal?
Upvotes: 0
Views: 422
Reputation: 13805
Changestreams are resilient against replica set elections and will continue as if nothing happened. From the changestream manual:
The change stream cursor remains open until one of the following occurs:
- The cursor is explicitly closed.
- An invalidate event occurs; for example, a collection drop or rename.
- The connection to the MongoDB deployment is closed.
- If the deployment is a sharded cluster, a shard removal may cause an open change stream cursor to close, and the closed change stream cursor may not be fully resumable.
All other events like replica set election will not affect the changestream.
For your second question, this is expected since your read preference is explicitly secondary
. To read from the primary if the secondary is not available, you want to use the secondaryPreferred setting.
Upvotes: 0