How does a MongoDB cluster get access?

Source: Internet
Author: User
Tags string format unix domain socket

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:
  1. mongodb://

    A required prefix to identify, that's a string in the standard connection format.

  2. 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 #.

  3. 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.

  4. :p Ort1

    Optional. The default value is : 27017 if not specified.

  5. Hostx

    Optional. You can specify as many hosts as necessary. You would specify multiple the hosts, for example, and connections to replica sets.

  6. :p Ortx

    Optional. The default value is : 27017 if not specified.

  7. /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.

  8. ? 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?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.