How can I copy MongoDB from one local folder to another local folder?

Searched for this topic but only found references for local to remote and vice versa. I have two projects in different folders, now I want to copy the content of one of the projects MongoDB over to the second project to start anew but with the whole database as a copy of the first MongoDB.

I can’t seem to physically find the MongoDB and not sure how I can copy the content of it over.

Thanks in advance for your help,

Andreas

meteor add constellation:dump-restore to each project is an easy way if you’ve only got a small amount of data (i.e. 1000s of documents rather than 10s of 1000s).

For larger data sets go straight for mongodump and mongorestore. Make sure both apps are running. App 1 on localhost:3000 (meteor – defaults to port 3000) and App 2 on localhost:4000 (meteor -p 4000 to make this happen):

In your console, navigate to the project root of App 1 (source project – e.g. cd ~/meteor-projects/myapp) and type these commands in the console:

mongodump -db meteor -h localhost -port 3001
mongorestore -db meteor -h localhost -port 4001 -drop

The -drop will drop collections in target app’s existing database. Remove that flag if you just add to add records from the source app the the db of the target app.

1 Like

@babrahams,

unfortunately it doesn’t work with mongodump/mongorestore.

I assume you mean opening a new terminal as the other ones is running the apps. I have two choices there, when I’m in the first app directory and enter the mongodump command it says it doesn’t know the command.

So I assume I first have to start: “meteor mongo” -> Right?

If I then enter the command again it recognizes it but I get the following error message:

SyntaxError: Unexpected identifier

I entered exactly your command, only difference is I copy from 4001 to 5001 as I have another connected app running at 3001 (which shares some data with the app at 4001)

Yes. Another terminal window/tab that isn’t the one with the app running.

No, don’t start meteor mongo. If it doesn’t know the command, it means you don’t have a global install of mongo with all its associated command line tools.

If you’re on a mac you can download mongo and install it via homebrew: brew install mongo (maybe brew install mongodb?) or download it from https://www.mongodb.com/ (although I notice they’ve made that a bit more difficult than it used to be).

How big is your db? It might be quicker to use Constellation’s dump-restore package.

I see, many thanks for your detailed expressions. My database in question is 0.531 GB big (or small, depends on where you come from).

I will give it a try and will look at the package you suggested.

No. Don’t use that package* for a 0.5Gb database – it’ll crash your browser for sure.

Better download and install mongo from somewhere.

* that Constellation package is just for the very early stages of development when there’s a bit of sample data in your db that you want to play around with, but when you also want to save it beforehand and restore it later if you stuff things up - author of the package speaking here :stuck_out_tongue:

1 Like

Thanks, was about to install it when I stumbled on their console “Constellation”. That one looks interesting to explore. Will try Mongo install (and I thought it’s installed already but anyway)

When you say “download and install Mongo from somewhere” I’ve checked the official MongoDB website and they only offer their commercial solution for download (and also for limited evaluation period): https://www.mongodb.com/lp/download/mongodb-enterprise?jmp=nav

Is that the one that I need to install? I was hoping there was just a simple tool or commands to this but it turns out into a major operation it seems. Unfortunately 531 MB of a database is too much too lose (wondering why it’s so big anyway)

Yeah, I saw that too and was less than impressed. Google around and see if you can find a simple download (preferably with an installer) for mongodb. Once mongo is installed on your dev machine, what you’re describing is as simple as a couple of lines in your terminal (the ones shown above).

Actually, new plan forming … DISCLAIMER: this might not work and might stuff up your db in App 2, but … using Finder (mac): go into .meteor/local/db in App 1 - select and copy to clipboard everything (files and folders) that you see there, than go to App 2’s .meteor/local/db and (first throw its contents in the trash) then paste the contents from the clipboard.

1 Like

You are a genius. Just copying the db folder did the job, completely painless. Thanks so much!

Here is the link of MongoDB package: https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/
Hope it will be helpful

Your are still a genius. Had some trouble with the same problem. Your solution was absolute the easiest way to do the job. Hat off. Thanks