Is there a simple way to export the data from a meteor deployed app?

Is there a simple way to export the data from a meteor deployed app?

So, for example, if I had deployed an app named test.meteor.com...

How could I easily download the data that has been collected by that app - so that I could run it locally with data from the deployed app?


To get the URL for your deployed site at meteor.com use the command (you may need to provide your site password if you password protected it):

meteor mongo --url YOURSITE.meteor.com

Which will return something like :

mongodb://client:[email protected]:27017/YOURSITE_meteor_com

Which you can give to a program like mongodump

mongodump -u client -h sky.member1.mongolayer.com:27017 -d YOURSITE_meteor_com\
          -p PASSWORD

The password is only good for one minute. For usage:

$ meteor --help mongo

And here's how to do the opposite: (uploading your local monogo db to meteor)

https://gist.github.com/IslamMagdy/5519514

# How to upload local db to meteor:

# -h = host, -d = database name, -o = dump folder name
mongodump -h 127.0.0.1:3002 -d meteor -o meteor

# get meteor db url, username, and password
meteor mongo --url myapp.meteor.com

# -h = host, -d = database name (app domain), -p = password, folder = the path to the dumped db
mongorestore -u client -h c0.meteor.m0.mongolayer.com:27017 -d myapp_meteor_com -p 'password' folder/

Based on Kasper Souren's solution I created an updated script that works with current versions of Meteor and also works when you protect your remote Meteor app with a password.

Please create the following script parse-mongo-url.coffee:

spawn = require('child_process').spawn
mongo = spawn 'meteor', ['mongo', '--url', 'YOURPROJECT.meteor.com'], stdio: [process.stdin, 'pipe', process.stderr]

mongo.stdout.on 'data', (data) ->
    data = data.toString()
    m = data.match /mongodb:\/\/([^:]+):([^@]+)@([^:]+):27017\/([^\/]+)/
    if m?
        process.stdout.write "-u #{m[1]} -p #{m[2]} -h #{m[3]} -d #{m[4]}"
    else
        if data == 'Password: '
            process.stderr.write data

Then execute it like this in a *nix shell:

mongodump `coffee parse-mongo-url.coffee`

I have created a tool, mmongo, that wraps all the Mongo DB client shell commands for convenient use on a Meteor database. If you use npm (Node Package Manager), you can install it with:

npm install -g mmongo

Otherwise, see README.

To back up your Meteor database, you can now do:

mmongo test.meteor.com dump 

To upload it to your local development meteor would be:

mmongo restore dump/test_meteor_com

And if you accidentally delete your production database:

mmongo test.meteor.com --eval 'db.dropDatabase()'   # whoops!

You can easily restore it:

mmongo test.meteor.com restore dump/test_meteor_com 

If you'd rather export a collection (say tasks) to something readable:

mmongo test.meteor.com export -c tasks -o tasks.json

Then you can open up tasks.json in your text editor, do some changes and insert the changes with:

mmongo test.meteor.com import tasks.json -c tasks --upsert

Github, NPM


I suppose your data is in a mongodb database, so if that's the case, the question is more mongo-related than meteor. You may take a look at mongoexport and mongoimport command line tools.

Edit (for example):

mongoexport -h flame.mongohq.com:12345 -u my_user -p my_pwd -d my_db -c my_coll

You need to install mongodb on your computer to have this command line tool, and obviously you need your mongodb informations. In the above example, I connect to MongoHQ (flame.mongohq.com is the host, '12345' is the port of your mongo server), but I don't know which Mongo host is actually used by the meteor hosting. If you tried the Meteor examples (TODOs, Leaderboard, etc.) locally, chances are you already installed Mongo, since it uses a local server by default.