I have deleted the documents of the collection by running deleteMany query on the shell and it returned acknowledged true and result.
Even after deleting around 1 million documents the size of the db is same while running show dbs command.
The delete query which I have executed on the shell:
db.getCollection('activity').deleteMany({createdAt:{$lte: 1565375400000}})
The result of the above query is:
{ "acknowledged" : true, "deletedCount" : 1199713 }
Before and after the query the output of show dbs command is:
admin 0.000GB
local 0.000GB
logDb 17.203GB
Why is it so that db size isn't decreased and what can I do to free that size?
MongoDB will not release the space back to disk. Instead, it'll reserve the space considering the future growth
The right way to run an housekeeping is by dropping unwanted collections or drop unwanted DB's (make sure to take backup) which would release the space back to OS
As you've already deleted the docs, I would suggest you to run the compact command during maintenance window (if its a critical environment) which will defrag all the data and indexes and release the space back to OS
https://docs.mongodb.com/manual/reference/command/compact/
Thank you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With