I have a sensor hooked up to a Raspi, gathering data using Mongo. Every few days I copy the database (using mongodump
) and then delete the Mongo files and restart the sensor.
I have had some trouble deleting/empytying Mongo, and would like to understand what I did wrong.
Initially, I used the commands:
use [database]
db.[nameOfOnlyCollection].remove({})
to empty the database (it only has one collection). Using the command db.[nameOfOnlyCollection].count()
I could verify that the collection was empty.
However, even after this, Mongo was still taking lots of space on the Raspi. More specifically these (seemingly Mongo-related) examples took up several gigs of space:
- /var/lib/mongodb
- /var/lib/mongodb/journal
- /var/log/mongodb
I then found an answer recommending the command db.dropDatabase()
to delete all entries in a database.
I now run both db.[nameOfCollection].remove({})
and db.dropDatabase()
and this has fixed the problem. Meaning, Mongo no longer takes up gigs worth of space. However, I'd like to understand what's going on.
What is the difference between the commands remove
and dropDatabase
? When should one use one, when the other? (I'm running both - is that just silly?) Also, does anyone know why Mongo was still taking up lots of space even after running remove
?
Any links to relevant reading would be appreciated. (But preferably readings on a "for Dummies" -level. To say I'm a Mongo noob would be an insult to actual Mongo noobs.)