Copying MongoDB from meteor.com

I start­ed deploy­ing my lat­est Mete­or app umeedoo.net to my own VPS and want­ed to use the data from my beta sys­tem host­ed at umeedoo.meteor.com.
First of all, I was sur­prised how sim­ple and easy it was to deploy using Mete­or Up (MUP). Some weeks before, I spend an entire day on installing the Mete­or envi­ron­ment on a Debian machine — now it’s less than 15 min­utes! One caveat though, it did not work for me on Debian, I had to drop my pre­vi­ous Debian VM and replaced it with Ubun­tu as MUP depends on Upstart and it seems rather tricky to replace Debian’s SysVinit with Upstart. Ok, dif­fer­ent sto­ry, but a bii­ig thanks to Arun­oda for the great work on MUP!!

So, how to db.copyDatabase(); the data from the original DB to yours?

The method sig­na­ture is db.copyDatabase("[app-name]_meteor_com", "[your-db-name]", "[meteor-mongo-domain]", "[username]", "[password]");
I’ll assume “app” to be the app name for sim­plic­i­ty.
Gen­er­al approach: get the Mon­goDB URL, extract all the para­me­ters above, log into your own Mon­goDB instal­la­tion and use db.CopyDatabase(); to move the data over.

All com­mands need to be exe­cut­ed on the same machine. (FYI, the user­name and pass­word get auto­mat­i­cal­ly gen­er­at­ed and it did not work to get the URL on my machine and use the user­name and pass­word on the server… strange though)
Thus, install Mete­or on your server curl https://install.meteor.com/ | sh.
Then, get the Mon­goDB URL meteor mongo --url app.meteor.com
It will look like this mongodb://client-fd532e7d:683a9a4e-1604-5729-07fd-df1ba7dcbbf9@production-db-a2.meteor.io:27017/app_meteor_com
The parts are

  • user­name: client-fd532e7d
  • pass­word: 683a9a4e-1604-5729-07fd-df1ba7dcbbf9
  • mete­or-mon­go-domain: production-db-a2.meteor.io:27017

Start a Mon­goDB CLI by typ­ing mongo.
In my case, the data­base cre­at­ed by the app and MUP was called “admin” (i.e. [your-db-name]=“admin”). How to find yours? Use “show dbs” in the Mon­goDB CLI to see which one is yours.
Then write “use [your-db-name]” to switch to your DB.
And final­ly, using the data from above: db.copyDatabase("app_meteor_com", "admin", "production-db-a2.meteor.io:27017", "client-2fbeb6ef", "1bd44ece-b3fa-7d1b-0046-83b917927f35");
will copy the data over in a few sec­onds.
When I tried first, I got an error about a dupli­cate key (the deployed app had cre­at­ed some data already), drop­ping the entire DB fixed it. Also, the user­name and pass­word are valid for a short time only, so may­be hav­ing to ter­mi­nals open is a good idea.

Ref­er­ences: Cloning Mon­goDB, Mete­or dump, Clone DB from meteor.com, Copy DB from one server to anoth­er

Leave a Reply

Your email address will not be published. Required fields are marked *