Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear all entries in Docker mongodb?

Tags:

docker

mongodb

Is there an easy way to clear a mongodb database running in docker?

Or possibly delete it all and create it again?

like image 255
Cisplatin Avatar asked Jun 24 '16 17:06

Cisplatin


People also ask

How do I delete all collections in MongoDB?

To delete all documents in a collection, pass an empty document ({}). To limit the deletion to just one document, set to true. Omit to use the default value of false and delete all documents matching the deletion criteria.

How do I force all Docker containers to delete?

Use the docker container prune command to remove all stopped containers, or refer to the docker system prune command to remove unused containers in addition to other Docker resources, such as (unused) images and networks.


1 Answers

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.

like image 136
Nauraushaun Avatar answered Sep 22 '22 16:09

Nauraushaun