The previous section provides a brief introduction to MongoDB's Cluster setup. I believe we are already familiar with it. After the cluster is built, we should consider how our program should access him.
How to read and write data and other operations. Here are some of my work in the use of a list for everyone as a reference.
The link string format of the official website is as follows:
Mongodb://[username:[email protected]]host1[:p ort1][,host2[:p Ort2],... [, hostn[:p Ortn]] [/[database][?options]]
Each part consists of the following:
mongodb://
A required prefix to identify, that's a string in the standard connection format.
Username:[email protected]
Optional. If specified, the client would attempt to log in to the specific database using these credentials after connecting to the C2>mongod instance. (if security authentication is set, the User name password section is required.) If the auth=true is not turned on. You do not need to configure the user name and password) Note: Follow the password followed by an @ symbol. It may be to differentiate between the password and the later section. So it's best not to include @ when setting a password. This causes MongoDB to read the password as before the first @ symbol by default. What to do if a password is included in the password. In C #, you only need to change the @ symbol in the password to%40, which is automatically converted to @ in C #.
Host1
This is the only required part of the URI. It identifies a server address to connect to. It identifies either a hostname, IP address, or UNIX domain socket.
:p Ort1
Optional. The default value is : 27017 if not specified.
Hostx
Optional. You can specify as many hosts as necessary. You would specify multiple the hosts, for example, and connections to replica sets.
:p Ortx
Optional. The default value is : 27017 if not specified.
-
/database
Optional. The name of the database to authenticate if the connection string includes authentication credentials in the form of username:[email protected] . If /database is not specified and the connection string Includes credentials, the driver would authenticate to the admin /tt> database. If it is a cluster. Database should be admin. Because password authentication is queried and validated in the Admin library. If you are setting up a database where you store data. There may be errors that the user does not exist. You need to be careful here.
? options
Connection specific options. See Connection String options for a full description of these Options.
If the connection string does not specify a database/you must specify a slash (i.e. /) between the last host N and the question mark that begins the string of options.
Instance:
mongodb://administrator:13579%40$^*) @12.0.0.1:30000,12.0.0.2:30000,12.0.0.3:30000/admin?slaveok=true; Readpreference=secondary
User name: Administrator
Password: [email protected]$^*]
Three access entrances MONGOs address: 12.0.0.1:30000,12.0.0.2:30000,12.0.0.3:30000
Slaveok=ture: Open from library readable. (Default from library not read/write)
Readpreference=secondary: Preference read from node. Turn on read and write separation. Please refer to the official website for additional configuration.
More content:
1.Windows Cluster Construction
2. How do I add user rights?
3. How to monitor whether the cluster environment is working properly.
4. How to do data distributed storage
5. How to choose the Tablet key?
6. Index Establishment
7.curd basic operation.
8. How to control the read and write separation.
9.c# php Java JS and so how to use the Mongod cluster?
For the above question. The next step is to update slowly.
How does a MongoDB cluster get access?