After deleting a large amount of data, why does the index become larger instead?

  mongodb, question

The historical data in the table has been deleted and only the data of the latest quarter has been retained.

Before deletion

"count": 1379345, # Total
 "size": 3823247286, # Size
 "nindexes" : 4,
 "totalIndexSize": 86913024, # index size
 "indexSizes" : {
 "_id_" : 12873728,
 "created_at_1" : 17534976,
 "storage_time_1" : 7397376,
 "guid_1" : 49106944
 },

After deletion

"count" : 453978,
 "size" : 2478837459,
 "nindexes" : 4,
 "totalIndexSize" : 89522176,
 "indexSizes" : {
 "_id_" : 12873728,
 "created_at_1" : 18096128,
 "storage_time_1" : 7397376,
 "guid_1" : 51154944
 },

Before deletion VS after deletion
count: 1379345 VS 453978 diff: 925,367
size: 3823247286 VS 2478837459 diff: 1,344,409,827
totalIndexSize: 86913024 VS 89522176 diff: -2,609,152

Why does the index size become larger after so much data is deleted?

In the WiredTiger engine, each index corresponds to a separate file on the disk. After deleting a large amount of data, the corresponding index in this file has also been deleted. But space will not be released, only as far as possiblereusing. Because in order to free up these spaces, free space must be concentrated at the end of the file and then truncated. No database will take the initiative to do this, which is inefficient and meaningless.
If you really want to do it, find outcompactCommand, both slow and blocking. It is strongly not recommended.