Skip to main content

[MongoDB] Read preference in a transaction must be primary

· One min read

MongoDB 4.0.3 ReplicaSet

MongoDB.Driver for .net Core 2.7.3

在 Connection String 中配置了 readPreference=secondaryPreferred:

mongodb://user:password@mongod-1:27017,mongod-2:27017,mongod-3:27017/DBName?connect=replicaSet&readPreference=secondaryPreferred

然后在一个 Transaction 中读取数据报错:"Read preference in a transaction must be primary", Transaction 中的读取不能使用 secondaryPreferred

ClustrMaps