数据库 - mongodb表查询问题?
阿神
阿神 2017-05-02 09:20:46
0
2
942

mongodb一个collection里存了日志,现在要进行统计分析。
因为是记录日志,所以经常插入信息,也就没有索引。但是分析查表的时候没有索引又特别慢。想问下有没有什么好的方法。暂时2000W数据量。

阿神
阿神

闭关修行中......

reply all(2)
巴扎黑

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

  1. Use sharding for transformation.
    You should already know what sharding is, no need to explain more. The problem brought by this solution 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 the path you must take, so plan ahead.

  2. Create different indexes on different replication set points
    If you are still running on a single node, it is recommended to upgrade to a replica set as soon as possible. There are many cases where single-node hardware failure causes data to be lost and cannot be recovered. Don’t wait until it happens before you regret it. Under the premise of replica sets, each result can be independently indexed.

    1. Stop node

    2. Remove the replica set configuration and start with different ports

    3. Build the index you need on this node

    4. Restart with original configuration

It should be noted that the replica set still needs to complete all write operations on the primary node, so too many indexes may still cause problems. Everything still needs to be tested by yourself to draw conclusions.

phpcn_u1582

Either add index or change to elasticsearch or hbase. It is recommended to change to elasticsearch as soon as possible

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template