Mongodb Table Query Problem?

  mongodb, question

Mongodb has a log in a collection and now it needs statistical analysis.
Because it is a log, so often insert information, there is no index. However, it is extremely slow to analyze the lookup table without indexes. I want to know if there is any good way. Temporary 2000W data volume.

Generally speaking, indexes should not have a very obvious impact on writing performance. Of course, if you need to add a lot of indexes, that is another matter. If you haven’t tried, it is recommended that you try the index you need first to see how much side effect it brings and whether it is within the acceptable range. If so, that’s good. The problem is solved. If not, consider the following two options:

  1. Use sharding to make modifications.
    You should already know what sharding is and not explain much. The problem brought by this scheme is obviously that the number of servers will increase significantly, which is also the inevitable result of horizontal expansion. In the long run, if your business moves forward, this is also the only way to go, so you can plan ahead.

  2. Create different indexes on different replication aggregation points
    If you are still running on a single node, it is recommended to upgrade to a replication set. There are many cases of single-node hardware failure that the data cannot be found. Don’t wait for it to happen before you regret it. On the premise of copying sets, each result can be independently indexed.

    1. Stop node

    2. Start after removing replication set configuration with different ports

    3. Build the index you need on this node.

    4. Restart in original configuration

It should be noted that the replication set still has to complete all writes on the primary node, so too many indexes may still cause problems. It’s still up to you to draw your own conclusions.