How do I use an existing MongoDB in a Meteor project?

In the comments to danny's answer Tom Wijsman recommends patching packages/mongo-livedata/mongo_driver.js, line 21. A better place is in app/meteor/run.js, line 460. This way the environment variable is still picked up if present, such as when running Meteor on Heroku. Just change the default hardcoded mongodb://127.0.0.1 to the location of your MongoDB server.


We use npm:

  • Create a package.json file with npm init, if you don't have one already.

  • Enter and modify the following line in that file (replacing all the <...>'s):

"scripts": {"meteor": "MONGO_URL=mongodb://<USER>:<PASSWORD>@<SERVER>:<PORT>/<DB> meteor"}
  • You can then start meteor with just npm run meteor

Use the environment variable MONGO_URL. Something like:

export MONGO_URL=mongodb://localhost:27017/your_db

Replace your_db with meteor or whatever db you want to use.


You can use db.copyDatabase to do this, with a caveat that there is a bug and you can't update the data in Meteor. See https://github.com/meteor/meteor/issues/61

If you're using the development version of Meteor, you can transfer data from a running MongoDB server by starting your Meteor app, then doing:

mongo --port 3002

This will connect you to the Meteor app's Mongo server. Now use db.copyDatabase like this:

db.copyDatabase('myappDatabase', 'meteor', 'localhost');

This will copy the database myappDatabase from a MongoDB server running on the standard port on localhost, to the Meteor app Mongo server. The database name the Meteor app uses is 'meteor'.

Tags:

Meteor