Things to note when creating indexes in MongoDB _mongodb

Source: Internet
Author: User
Tags create mongodb mongodb mongodb server

Last week in Ruby-china posted "MongoDB those pits", reflected quite enthusiastic, many reply very insightful, one of the children's shoes in-depth mention of the MongoDB indexing method, which led me to a more in-depth understanding of the MongoDB index method and some considerations.

In the MongoDB, it is mentioned that running the index command directly at the front desk will cause the entire database to block, so the index is recommended to be built using the background method. However, this also poses a problem, before version 2.6, in the secondary server even if the background way of indexing, secondary will be indexed in a foreground way, which causes the secondary also raises the database blocking Plug problem. The 2.6 version fixes the bug,2.6 version and then uses the background method to build the index, and actually turns to the background to run.

In order to minimize the impact of indexing on MongoDB server, one approach is to create MongoDB server after converting it to standalone mode. The following are specific practices:

1. Stop the secondary server first, restart MongoDB after canceling the--replset parameter and changing the MongoDB port, at which point MongoDB will enter the standalone mode;

2. In standalone mode to run the command Ensureindex index, it is recommended to use the foreground mode of operation;

3. After indexing, shut down secondary server and start in normal way;

4. According to the above 1~3 steps to secondary indexing, and finally the primary server temporarily converted to secondary server, the same as the 1~3 index, and then convert it to primary server.

This approach is still troublesome, but it is possible to minimize the impact of indexing operations on MongoDB, and in some cases it is worth doing.

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.