Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import data to Docker-container's mongodb

Tags:

docker

mongodb

I have mongo database that I used to use. But now I have to switch everything to docker container. while switching I am not being able to import data from local machine mongo-db to container mongo-db.

How can I import all the data from local mongodb to container's mongodb?

like image 743
Laxmi Prasad Avatar asked Sep 17 '25 16:09

Laxmi Prasad


1 Answers

A strategy you can follow is to use mongodump and mongorestore (refer to https://docs.mongodb.com/manual/reference/program/mongodump/ )

Mongodump and restore are preferred over the export and import variants, since the latter one use JSON and cannot preserve al BSON data-types.

Depending on how you manage the database file storage in your container, you either make the 'dump' available on a file-share that is mounted by the container or make it available in a container volume. That information can be found here: https://docs.docker.com/reference/samples/mongodb/

like image 199
Michaël van der Haven Avatar answered Sep 20 '25 08:09

Michaël van der Haven