Clear all entries in Docker mongodb?
13,950
Solution 1
There are a number of ways:
- The same way you would normally clear a mongodb database. You're running it in Docker, but it is a real mongodb after all. See this, and this.
- If you've mounted your database's data as a volume on the host system using -v on the docker run command, you can just clear this folder out.
- If you haven't, the data lives in the container. You can remove the container and recreate it (docker rm container_name). Or run a shell in the container and remove the data from the container's filesystem (docker exec -it container_name bash).
Regarding the last option, you shouldn't be in this scenario because your data should live on the host system and your container should be disposable.
Solution 2
docker exec -it mongodb_container bash -c "mongo db-name --eval 'db.dropDatabase()'"
![Cisplatin](https://i.stack.imgur.com/Uc6uH.jpg?s=256&g=1)
Author by
Cisplatin
Updated on July 20, 2022Comments
-
Cisplatin almost 2 years
Is there an easy way to clear a mongodb database running in docker?
Or possibly delete it all and create it again?
-
obesechicken13 about 6 yearsYou can also delete volumes using docker volume rm <volume_name>