C# MongoDb 连接到副本集问题 [英] C# MongoDb Connect to Replica Set Issue

查看:53
本文介绍了C# MongoDb 连接到副本集问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 mongodb 网站,如果我只从副本集中给它一个成员,我应该能够连接到副本集:

According to the mongodb website, I should be able to connect to a replica set if I just give it one member from the replica set:

"即使种子列表不完整,C#驱动程序也能够连接到副本集.只要种子列表中至少有一台服务器,即使它不在种子列表中,它也会找到主服务器列表响应(响应将包含完整的副本集和当前主节点的名称)."http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Connectionstrings

"The C# Driver is able to connect to a replica set even if the seed list is incomplete. It will find the primary server even if it is not in the seed list as long as at least one of the servers in the seed list responds (the response will contain the full replica set and the name of the current primary)." http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Connectionstrings

但是,如果我只给它一个辅助成员,我无法让我的驱动程序连接.

However, I cannot get my driver to connect if I just give it a secondary member.

这是我当前的连接语句:

This is my current connection statement:

m_server = MongoServer.Create(new MongoServerSettings { ConnectionMode = ConnectionMode.ReplicaSet, Server = new MongoServerAddress(connection) });

'connection' 变量是:mongodb://servername/?safe=true

The 'connection' variable is: mongodb://servername/?safe=true

我看到了这个:https://jira.mongodb.org/browse/CSHARP-500,我确实运行了 rs.status(),并且确实使用了正确的服务器名称.任何帮助表示赞赏!

I saw this: https://jira.mongodb.org/browse/CSHARP-500, and I did run rs.status(), and did use the correct server name. Any help is appreciated!

推荐答案

所以,连接变量是一个完整的连接字符串,而不是传递给 MongoServerAddress 的东西.此外,您还可以在连接字符串上指定连接模式.试试这个:

So, the connection variable is a full connection string, not something to pass to MongoServerAddress. Also, you can specify the connection mode on the connection string as well. Try this:

connection = "mongodb://servername/?safe=true&connect=replicaset";
m_server = MongoServer.Create(connectionString);

这篇关于C# MongoDb 连接到副本集问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆