Driver工具类和mongodb交互的时候报错
连接代码
var mongodbClient = "mongodb://MyMongoDB:123456@localhost:27017/MyDataBase?readPreference=primaryPreferred&replicaSet=Mylocalhost&authSource=MyDataBase";
报错信息
A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [] }.
你把问号后面的内容去掉试试,问号前面就够了
var mongodbClient = "mongodb://MyMongoDB:123456@localhost:27017/MyDataBase";
噗,现在好了,为啥问号后面加上就不可以,我拷贝同事的老代码的
@重生时空之门: 直接连接不需要后面的内容,问号后面的内容是用在配置了主从数据库的情况下的,一般用不到