C# 了解 MongoDb 连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16614904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Understanding MongoDb connection strings
提问by amateur
I am working with Mongodb as a database for my asp.net mvc front end site. I have MongoDB running on 3 servers, in a replica set, a primary, secondary and an arbiter. Connecting to this is the 3 front end web servers that performs CRUD operations on the data held in Mongo. I have a number of questions on my setup that I would like clarification on.
我正在使用 Mongodb 作为我的 asp.net mvc 前端站点的数据库。我在 3 个服务器上运行 MongoDB,在一个副本集中,一个主服务器、一个辅助服务器和一个仲裁服务器。连接到此的是 3 个前端 Web 服务器,它们对 Mongo 中保存的数据执行 CRUD 操作。我有一些关于我的设置的问题,我想澄清一下。
This is my connection string from C#
这是我来自 C# 的连接字符串
server=myprimary.com:27017,mysecondary.com:27017;replicaset=MySet;safe=true;database=MyDatabase
Is it correct not to include arbiter in this connection string?
在此连接字符串中不包含仲裁器是否正确?
When I work with sql server, I set up all my connection strings with integrated security. What is the best practise for similar in Mongo connection strings?
当我使用 sql server 时,我设置了所有具有集成安全性的连接字符串。Mongo 连接字符串中类似的最佳实践是什么?
回答by Abhishek Kumar
Is it correct not to include arbiter in this connection string?
在此连接字符串中不包含仲裁器是否正确?
You don't need to provide the arbiter details, it will be automatically discovered by your app-driver.
您不需要提供仲裁者的详细信息,它会被您的应用程序驱动程序自动发现。
The only thing you can provide in mongoURI is SSL option or username and password for the database that you want to connect. But let me remind you, some of the driver don't honor SSL or 'username' and 'password' in mongoURI.
您可以在 mongoURI 中提供的唯一内容是您要连接的数据库的 SSL 选项或用户名和密码。但是让我提醒您,某些驱动程序不支持 mongoURI 中的 SSL 或“用户名”和“密码”。
http://docs.mongodb.org/manual/reference/connection-string/#uri.ssl
http://docs.mongodb.org/manual/reference/connection-string/#uri.ssl
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
回答by Craig Wilson
I'd suggest you consult the documentation. It can answer most of your questions. In addition, I see you are using the alternative connection string syntax. I'd highly suggest changing to the other connection string format as we will likely be deprecating the version you are using. The equivalent connection string would be
我建议你查阅文档。它可以回答您的大部分问题。此外,我看到您正在使用替代连接字符串语法。我强烈建议更改为其他连接字符串格式,因为我们可能会弃用您正在使用的版本。等效的连接字符串将是
mongodb://myprimary.com:27017,mysecondary.com:27017/MyDatabase/?replicaset=MySet.
Finally, you'll find documentation at the previous link regarding authentication. We don't have the "integrated security" option, but we do support SSPI integration (also called GSSAPI and kerberose). You'll find it referred to as External Authentication in our documentation. The caveat is that the MongoDB server you are running will need to be on a linux box and setup with kerberos. This can be a complicated processwhen used in conjunction with Active Directory to get the keytab file out.
最后,您将在上一个链接中找到有关身份验证的文档。我们没有“集成安全”选项,但我们支持 SSPI 集成(也称为 GSSAPI 和 kerberose)。您会在我们的文档中发现它被称为外部身份验证。需要注意的是,您正在运行的 MongoDB 服务器需要在 linux 机器上并使用 kerberos 进行设置。当与 Active Directory 结合使用以获取密钥表文件时,这可能是一个复杂的过程。

