search

Home  >  Q&A  >  body text

mongodb - mongo删除文档导致索引变大

我们使用的是副本mongo,有一个collection中大概有1.5亿条记录,[size=10GB,Storage Size=3.4GB,Total Index Size:6GB]
因为是保存的历史记录,我们使用remove删掉30天前的记录(大概200万),但是发现索引大小从6GB涨到9GB.

请问该如何正确的删除历史记录?

阿神阿神2858 days ago769

reply all(2)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-02 09:24:42

    Generally, no special operation is required to delete it. The Btree used by MongoDB is also self-balancing and does not need to be rebuilt. Except for a bug SERVER-21063 in 3.0.7 and earlier versions that will affect the balance of the btree, I have not heard of anything special that needs attention.
    This situation of increasing from 6G to 9G has never been heard of. You can see if the same is true for slave nodes. If possible, for verification purposes, delete the index on a slave node and recreate it to see if the size is different.
    Edit: You can try compact to see if it works before trying it. Pay attention to the impact on the instance. It is best to separate a secondary and test it separately.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-02 09:24:42

    This is explained in the document. When deleting data, the index will not be deleted. Even if you delete the entire collection, the index will not be deleted. So at this time, I suggest you rebuild the index.

    reply
    0
  • Cancelreply