Docker
November 25, 2020

Mongo migrate in Docker container

For example, we'll do it in inc3 image.

First of all, we need to do base migration in api bash:

./bin/console mongodb:migrations:migrate -n -e dev

Need to create a table in mongo: TotalFlow

./bin/console app:compute:totalflow stp ( stp - it's a project domain)

If you want to create the table BasePlan in mongo

./bin/console intr:base:plan '01...' ('01...' - project_id)

Import data

We'll do it for TotalFlow

Add data file in mongo container:

docker cp /home/dev/TotalFlow.bson intr_mongo:/tmp

Real for my dev pc:

docker cp /home/dev/Documents/dump/mongo/initiator/BasePlan.bson intr_mongo:/tmp
docker cp /home/dev/Documents/dump/mongo/initiator/CompanyUser.bson intr_mongo:/tmp
docker cp /home/dev/Documents/dump/mongo/initiator/Log.bson intr_mongo:/tmp
docker cp /home/dev/Documents/dump/mongo/initiator/TaskAction.bson intr_mongo:/tmp
docker cp /home/dev/Documents/dump/mongo/initiator/TotalFlow.bson intr_mongo:/tmp
docker cp /home/dev/Documents/dump/mongo/initiator/TV.bson intr_mongo:/tmp

// (intr_mongo - it's my container)

Run bash for this container:

docker-compose -p inc3 exec mongo bash

Need to run:

mongorestore --db=initiator /tmp/TotalFlow.bson

Real for my dev pc:

mongorestore --db=initiator /tmp/BasePlan.bson
mongorestore --db=initiator /tmp/CompanyUser.bson
mongorestore --db=initiator /tmp/Log.bson
mongorestore --db=initiator /tmp/TaskAction.bson
mongorestore --db=initiator /tmp/TotalFlow.bson
mongorestore --db=initiator /tmp/TV.bson

Remove useless files:

rm -f /tmp/BasePlan.bson
rm -f /tmp/CompanyUser.bson
rm -f /tmp/Log.bson
rm -f /tmp/TaskAction.bson
rm -f /tmp/TotalFlow.bson
rm -f /tmp/TV.bson

Additional information:

https://docs.mongodb.com/database-tools/mongorestore/#bin.mongorestore

Done!