百度智能云

All Product Document

          Cloud Database MONGODB

          Best practices for use of MongoDB

          The replica set (single node, three nodes) and shard set instances can be created through Baidu Cloud MongoDB management console. This article will introduce the specific operations for purchase and use of MongoDB.

          Preconditions

          • Baidu cloud account has been registered.
          • To create an instance of post-payment, please make sure the account balance is greater than 0 Yuan.

          Fee description

          Refer to Product Pricing for details.

          Operation procedures

          Purchase MongoDB instance

          1. Log in to Baidu cloud control system, and select the cloud database DocDB for MongoDB product to enter into the instance purchase page for operation.
          2. Choose the payment method, database deployment region and available zones.

          image.png

          1. Select the specification configuration of MongoDB cloud database.

            Selection of replica set architecture configuration:

            image.png

            Selection of shard cluster architecture:

          1. Set MongoDB system information, such as: Instance name, account password, etc..

          image.png

          1. Select purchase information, such as prepayment setting purchase time, purchase quantity and automatic renewal fee.

          image.png

          1. Click Next to enter the payment interface. Click Pay, and pay successfully, then the system will automatically create MongoDB cluster.

          Set whitelist for MongoDB instance

          Baidu cloud database MongoDB can set the IP source that is allowed to access this instance through whitelist,the formats supported include IP and CIDR (network segment). In order to ensure the data security, the whitelist is defaulted as empty after the cloud database MongoDB instance is created, indicating that no external device is allowed to access the instance.

          Description:

          • Before using the target instance for the first time, it is required to set the white list of the instance. Only after adding the white list, the instance connection information can be displayed on the basic information page of the instance.
          • At present, the upper threshold of adding or deleting white list at one time is 50.
          1. Select the region where the instance is located at the upper left corner of the console page, enter the "DocDB for MongoDB" page.
          2. Click the Replica Set Instance List or Shard Set Instance List on the left navigation bar.
          3. Find the target instance and click the instance name to enter the instance details page.
          4. Click white list in the left navigation bar to view the white list.
          5. Click Add IP Address, enter the white list to be added in the pop-up dialog box, and click OK to add successfully.
            image.png

          Description:

          • IP addresses are separated by English commas and cannot be duplicated. The formats supported include: 192.168.0.1(IP), 10.11.12.13/24 (CIDR mode, classless inter-domain routing, indicates the length of prefix in address, ranging from 1 to 32).
          • 0.0.0.0/0 indicates that no restriction on IP access is set, and the database will have high security risks. It is recommended to set only the IP or IP segment of your application server as accessible.

          Configure alarm strategy for MongoDB instance

          The cloud database DocDB for MongoDB provides instance status monitoring and alarm functions, informing users of the abnormalities of monitoring item data at the first time based on the setting of alarm strategies for important monitoring items, so that user can locate and handle the faults quickly. Based on past experience, it is strongly recommended that users set alarm strategies for maximum number of links and disk usage.

          1. Select the region where the instance is located at the upper left corner of the console page, enter the "DocDB for MongoDB" page.
          2. Click the Replica Set Instance List or Shard Set Instance List on the left navigation bar.
          3. Find the target instance and click the instance name to enter the instance details page.
          4. Click Monitor in the left navigation bar, select the node to set alarm strategy according to your requirements, and click alarm details at the top of the page to enter the alarm management page of the instance to set alarm strategy.

            image.png

          5. Click the alarm strategy in the upper navigation bar to enter the alarm strategy page of cloud monitoring BCM platform, on the page, user can add alarm strategies and create alarm actions against abnormality, insufficient data and for recovery to normal.

            image.png

          6. Click Add Strategy to add an alarm strategy, define alarm strategy information, and check the corresponding alarm action, then click Save to finish the adding step.

            image.png

          Strategy information description

          Strategy information Description
          Name Name of alarm strategy
          Monitoring item Monitoring indicators of alarm strategy should be set
          Statistical period 5 minutes by default. Optional values include: 1 min, 5min, 10min, and 15min
          Statistical method The default value is the average value. Optional values include: average value, sum value, maximum value and minimum value
          Threshold Alarm threshold of monitoring item
          Alarm after repeating several times 1 time by default. Optional values range from 1 time to 10 times
          Alarm level Important by default. Optional values include critical, notification, important, and warning
          1. Click Alarm Action in the upper navigation bar to enter the alarm action page, then add corresponding alarm actions according to your own situation.

            image.png

          2. Click Create Action

            image.png

          3. Enter into the page of Create Alarm Action, fill in the basic information and notification information of alarm action, and save to complete the creation.

          Alarm action parameter description

          Parameter Description
          Action name Name of alarm action
          Available region The alarm actions in different regions are only applicable to the alarm strategies in each respective region
          Notification means Baidu smart cloud currently supports "Email notification", "SMS Notification", "Telephone Notification", and the combined notification form of the three
          Notified object Support "User Group" and "User"
          If you do not have a created notified object at present, you can click "Add User Group" or "Add User" to create it
          Timed close Timed close is optional

          Description:

          Mongo Shell Connects MongoDB Instance

          Mongo Shell is a database management tool self-built in MongoDB database, user can create BCC in VPC where the instance is located and install Mongo Shell tool on it, then connect the replica set instance through Mongo Shell.

          Preconditions

          To ensure successful authentication, please install Mongo Shell of the version corresponding to MongoDB instance version. IP addresses of clients have been added to the white list of MongoDB instance.

          1. Select the region where the instance is located at the upper left corner of the console page, enter the "DocDB for MongoDB" page.
          2. Click the Replica Set Instance List or Shard Set Instance List on the left navigation bar.
          3. Find the target instance and click the instance name to enter the instance details page.
          4. In the instance Basic Information, get the node connection address and instance address
          5. Connect instance on the client end where Mongo Shell is installed in the following ways.
          • Single node connection mode

          During daily testing, user can directly connect the Primary/Secondary node. It should be noted that once the Master-slave switch occurs, the role of connecting node will change, which will affect the read-write operation. ​
          Command format:

          mongo --host <host> -u <username> -p --authenticationDatabase <database>
          Description: 
          <host>:connection address of Primary node or Secondary node. 
          <username>:Database account number of MongoDB instance, the initial account number is root.
          <database>:Authentication database name, i.e., the database to which the database account belongs. When the database account number is root, the corresponding database is admin.

          Examples

          mongo --host XQgIft8n4.mongodb.bj.baidubce.com:27017 -u root -p **** --authenticationDatabase admin

          User only needs to replace**** with account password.

          • Highly available connection mode.

          Use ConnectionStringURI to connect the database to ensure the connected node is always the Primary node, and the read and write operation of the application will not be affected by the master-slave switching.

          Command format:

          mongo "ConnectionStringURI"

          Example:

          mongo "mongodb://root:****@XQgIftoqm.mongodb.bj.baidubce.com:27017,XQgIft8n4.mongodb.bj.baidubce.com:27017/admin?replicaSet=rep-zNo2RD"

          User only needs to replace **** with account password.

          Previous
          Best Practices for MongoDB Data Migration
          Next
          Best practices for MongoDB parameter configuration