@@ -13,58 +13,58 @@ General information about connecting to MongoDB servers.
13
13
14
14
### Connection String
15
15
16
- The [ connection string] ( http://docs.mongodb.org/manual/reference/connection-string/ ) is the simplest way to connect to one or more
16
+ The [ connection string] ( http://docs.mongodb.org/manual/reference/connection-string/ ) is the simplest way to connect to one or more
17
17
MongoDB servers. A connection string mostly follows [ RFC 3986] ( http://tools.ietf.org/html/rfc3986 ) with the exception of the domain name.
18
- For MongoDB, it is possible to list multiple domain names separated by a comma. Below are some example connection strings.
18
+ For MongoDB, it is possible to list multiple domain names separated by a comma. Below are some example connection strings.
19
19
20
20
21
21
- For a standalone mongod, mongos, or a direct connection to a member of a replica set:
22
-
23
- ```
22
+
23
+ ```ini
24
24
mongodb://host:27017
25
25
```
26
26
27
27
- To connect to multiple mongos or a replica set:
28
28
29
- ```
29
+ ```ini
30
30
mongodb://host1:27017,host2:27017
31
31
```
32
32
33
33
The [ authentication guide] ({{< relref "authenticating.md" >}}) contains information on how to provide credentials.
34
34
35
35
#### The Database Component
36
36
37
- The database component is optional and is used to indicate which database to authenticate against. When the database component is not
38
- provided, the "admin" database is used.
37
+ The database component is optional and is used to indicate which database to authenticate against. When the database component is not
38
+ provided, the "admin" database is used.
39
39
40
- ```
40
+ ``` ini
41
41
mongodb://host:27017/mydb
42
42
```
43
43
44
44
Above, the database by the name of "mydb" is where the credentials are stored for the application.
45
45
46
- > Note that some drivers utilize the database component to indicate which database to work with by default. The Java driver, while it
47
- parses the database component, does not use the database component for anything other than authentication.
46
+ > Note that some drivers utilize the database component to indicate which database to work with by default. The Java driver, while it
47
+ parses the database component, does not use the database component for anything other than authentication.
48
48
49
49
#### Options
50
50
51
- Many options can be provided via the connection string. The ones that cannot may be provided in a ` MongoClientOptions ` instance. To
52
- provide an option, append a ` ? ` to the connection string and separate options by an ` & ` .
51
+ Many options can be provided via the connection string. The ones that cannot may be provided in a ` MongoClientOptions ` instance. To
52
+ provide an option, append a ` ? ` to the connection string and separate options by an ` & ` .
53
53
54
- ```
54
+ ``` ini
55
55
mongodb://host:27017/?replicaSet =rs0&maxPoolSize =200
56
56
```
57
57
58
58
The above connection string sets the "replicaSet" value to "rs0" and the "maxPoolSize" to "200".
59
59
60
- For a comprehensive list of the available options, see the [ MongoClientURI] ( http://api.mongodb.org/java/3.0/com/mongodb/MongoClientURI.html )
60
+ For a comprehensive list of the available options, see the [ MongoClientURI] ( http://api.mongodb.org/java/3.0/com/mongodb/MongoClientURI.html )
61
61
documentation.
62
62
63
63
64
64
### MongoClient
65
65
66
- A ` MongoClient ` instance will be the root object for all interaction with MongoDB. It is all that is needed to handle connecting to
67
- servers, monitoring servers, and performing operations against those servers. Without any arguments, constructing a ` MongoClient `
66
+ A ` MongoClient ` instance will be the root object for all interaction with MongoDB. It is all that is needed to handle connecting to
67
+ servers, monitoring servers, and performing operations against those servers. Without any arguments, constructing a ` MongoClient `
68
68
instance will connect to "localhost" port 27017.
69
69
70
70
``` java
@@ -77,7 +77,7 @@ Alternatively, a connection string may be provided:
77
77
MongoClient client = new MongoClient (new MongoClientURI (" mongodb://host:27017,host2:27017/?replicaSet=rs0" ));
78
78
```
79
79
80
- Finally, the ` MongoClientOptions ` class provides an in-code way to set the same options from a connection string. This is sometimes
80
+ Finally, the ` MongoClientOptions ` class provides an in-code way to set the same options from a connection string. This is sometimes
81
81
necessary, as the connection string does not allow an application to configure as many configuration options as ` MongoClientOptions ` .
82
82
` MongoClientOptions ` instances are immutable, so to create one your application uses a builder:
83
83
@@ -91,7 +91,7 @@ in code but others via the connection string:
91
91
92
92
``` java
93
93
94
- MongoClientURI uri = new MongoClientURI (" mongodb://host:27017,host2:27017/?replicaSet=rs0" ,
94
+ MongoClientURI uri = new MongoClientURI (" mongodb://host:27017,host2:27017/?replicaSet=rs0" ,
95
95
MongoClientOptions . builder(). cursorFinalizerEnabled(false ))
96
96
MongoClient client = new MongoClient (uri);
97
97
```
0 commit comments