How to shrink index of partly cleaned mongodb collection?

Description

Hi there!
I have a mongodb related question.
We use Detailed Read Receipts (Admin UI - Message - Detailed Read Receipts) and collection rocketchat_message_read_receipt is about 2/3 of whole our mongodb size.
We decided to store only one month read receipts and I cleared that collection to only most recent read receipts are retain in db
I did it with command
db.rocketchat_message_read_receipt.remove( { ts: { $lte: ISODate("2021-04-14T08:58:00.000Z") } } )

Now I have much less size of that collection, but still same (15Gb) size of indexes of that collection

How can I clean that indexes?
reIndex is not recommdended for replica set deployments like RocketChat

Before


After
image

Here said that mongo handles that task, but it’s not true. Index size is still same

Server Setup Information

  • Version of Rocket.Chat Server: 3.14.0
  • Operating System: CentOS7
  • Deployment Method: docker
  • Number of Running Instances: 26
  • DB Replicaset Oplog: Enabled
  • NodeJS Version: 12.22.1
  • MongoDB Version: 4.0.24 WiredTiger
  • Proxy: nginx + HAProxy
  • Firewalls involved: No

Any additional Information

Thread at open server

1 Like

Partly solution for our situation is to drop indexes with db.rocketchat_message_read_receipt.dropIndexes()
That cleaned all indexes but main _id index.
Better then nothing

2 Likes