Compact doesn't free space

MongoDB three-node replica set, version v4.4.5.
I removed some data in the collection on the PRIMARY node, and then I executed the compact command on the SECONDARY node, but the freeStorageSize was not released after execution, why?

local-mongodb-one:SECONDARY> db.test_catch.stats()
{
        "ns" : "mdworkflow.test_catch",
        "size" : NumberLong("5555713675259"),
        "count" : 18994123,
        "avgObjSize" : 292496,
        "storageSize" : 811467612160,
        "freeStorageSize" : 30761287680,
        "capped" : false
}
local-mongodb-one:SECONDARY> db.runCommand({ compact:"test_catch" } )
{ "bytesFreed" : 0, "ok" : 1 }
local-mongodb-one:SECONDARY> db.test_catch.stats()
{
        "ns" : "mdworkflow.test_catch",
        "size" : NumberLong("5555714175181"),
        "count" : 18994126,
        "avgObjSize" : 292496,
        "storageSize" : 811467612160,
        "freeStorageSize" : 30761205760,
        "capped" : false
}

You could try updating to the latest patch release and attempt the compact again. 4.4.5 contains a patched critical issue and is not recommended for production use.

Your database could also be hitting https://jira.mongodb.org/browse/SERVER-41596

As an alternative to compaction you could resync the node.

I have deployed a replica set of MongoDB with the same version, and it has been verified that executing “compact” releases disk space in the new environment.

The data in this environment was originally migrated from v3.4.24 to v4.4.5. I am not sure if this has any impact on the issue. Resyncing the replica node data does release space, but it is too time-consuming. My intention is to solve the problem of why “compact” does not release disk space in this environment.

If you have any better ideas, please let me know. Thank you very much.

A post was split to a new topic: Compact run on primary no space released

Hello , I am facing same issue with my mongo db setup. I have 3 server mongo cluster. Here, 2 Servers are act as replication of Primary Server. After running db.collectionname.deletemany(), i am executing “db.runCommand({compact: ‘collectionname’,force: true});” . Both commands are executed successfully but compact is not able to release disk space. It is showing “0 bytes free”. My Mongo DB Version is 5.0.7
rs1:PRIMARY> db.runCommand({compact: ‘cdr’,force: true});
{
“bytesFreed” : 0,
“ok” : 1,
“$clusterTime” : {
“clusterTime” : Timestamp(1709533620, 1),
“signature” : {
“hash” : BinData(0,“AAAAAAAAAAAAAAAAAAAAAAAAAAA=”),
“keyId” : NumberLong(0)
}

    },

“operationTime” : Timestamp(1709533620, 1)
}
Thanks,
Ashish Pandya

Hello All, This is to inform you all that compact command is executed successfully on Primary and Free Disk Space is reclaimed successfully. Main reason is that If Mongo DB server doesn’t have enough disk space , Compact command will not able to free disk space. For example, Linux server which is used as Mongo have 8 GB of total disk space. Now , Some Data is seeded in Mongo DB hence Mongo DB is used 7 GB of data. OS/Server has available space of 1 GB only. Now, when we delete data of 500 MB and try to run compact, it won’t be able to free up bytes. You have to delete more data from mongo if you want to execute compact command or you can extend disk space size from 8 Gb to 16 GB in same mount point where Mongo DB is installed and occupied disk space.