DEV Community

loading...
Cover image for Mongo export-import

Mongo export-import

Visakh Vijayan
Willing to learn anything and everything exciting. Always awake. Skips food for fun.
Updated on ・1 min read

So I have my local setup of nestjs with mongodb. And I have this issue to sync the local database with live one everytime. The method I am using write now is as follows

mongodump -d <db> -o <folder> 

Enter fullscreen mode Exit fullscreen mode

This folder is inside my git directory. This is then pushed to the live directory.

In the live server I use

mongorestore -d <db> <folder-to-git>

Enter fullscreen mode Exit fullscreen mode

Although this works for me now during the development phase it stills consumes a bit of time.

P.S. I want a solution without opening ports. :D

Furthermore I have added them to the package.json file as follows -


    "dump": "mongodump -d <db> -o src/dbdump/",
    "restore": "mongorestore -d <db> src/dbdump/<db>"   

Enter fullscreen mode Exit fullscreen mode

Discussion (0)