郑州声乐培训班:Mongodb Connection Strings (auth user)

来源:百度文库 编辑:九乡新闻网 时间:2024/05/01 22:45:52

Connection Strings

  • Page History

Creating ConnectionStrings via code

The simples way to create an ConnectionString is to create MongoConnectionStringBuilder class, fill its properties and cal ToString().

var builder = new MongoConnectionStringBuilder();builder.Username = "test";var mongo = new Mongo(builder.ToString());

Formatting

The driver supports two ways of declaring ConnectionStrings. The MongoDB Url style and the ADO.NET style.

MongoDB Url style

Format: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]?property1=value&property2=value (not case sensitive)

Example: mongodb://test:foo@localost:1234,server2:1234/admin?pooled=true

ADO.NET style

Format: property1=value;propery2=value (not case sensitive)

Example: Server=localhost:1234,server2:1234;Username=test;Password=foo;Pooled=true;

Property overview

  • Username (Default: ,Alias: "user id","user"): Authentication username (leave empty if no auth is required)
  • Password (Default: ): Authentication password (leave empty if no auth is required)
  • Pooled (Default: true): If true the driver uses connection pooling
  • Database (Default: "admin", Alias: "data source"): The database which is used when the ConnectionString is used to create a MongoDatabase directly instead of using a Mongo object.
  • MaximumPoolSize (Default: 100, Alias: "max pool size"): Controls how much connection the pool can grow to.
  • MinimumPoolSize (Default: 0, Alias: "min pool size"): Controls how much connection the pool keeps open. The pool ensures the connections are opened when the first connection is requested
  • ConnectionLifetime (Default: , Alias: "connection lifetime"): Controls how long the pool an unused connection keeps open.
  • ConnectTimeout (Default: 15, Alias: "connecttimeout"): Controls how many seconds the driver waits before its throws an exception if a connection dose not receives or sends data.
  • Server: (Default: localhost:27017, Alias: "servers"): A list of servers the driver should connect to. If more the one server is given, the driver automatically assumes it connects to a replicaset.

download.rar