How to use existing MongoDB in a Meteor project?

Let's say there is a MongoDB server for a GUI client ( wxPython ) for a while.

How can I connect my new Meteor project to an existing MongoDB ?

+83
meteor
May 14 '12 at 17:15
source share
7 answers

Use the environment variable MONGO_URL. Something like:

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

Replace your_db with meteor or any other db that you want to use.

+152
Oct 21 '12 at 9:35
source share

We use npm :

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

  • Enter and change the following line in this file (replacing all <...> ):

 "scripts": {"meteor": "MONGO_URL=mongodb://<USER>:<PASSWORD>@<SERVER>:<PORT>/<DB> meteor"} 
  • Then you can start the meteor with npm run meteor
+14
Feb 07 '16 at 17:26
source share

Tom Weisman recommends patch packages / mongo-livingata / mongo_driver.js, line 21. The best place in the application / meteor / mileage .js, line 460. Thus, the environment variable is still preserved, if present , for example, when running Meteor on Heroku. Just change the default hardcoded mongodb: //127.0.0.1 to the location of your MongoDB server.

+9
Nov 13
source share

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

If you use the development version of Meteor, you can transfer data from a running MongoDB server by running the Meteor application, and then run:

 mongo --port 3002 

This will bring you to the Meteor app Mongo server. Now use db.copyDatabase as follows:

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

This will copy the myappDatabase from the MongoDB server running on the standard port on localhost to the Mongo application Meteor server. The name of the database that the Meteor application uses is "meteorite."

+4
Oct 19 '12 at 12:33
source share

Just copy the data to the Meteor MongoDB database - there is no reason to try to connect Meteor to an existing database and risk overwriting things.

Use mongoexport to dump your collections separately, and then mongoimport to import files into a database named meteor in a Meteor MongoDB instance. The Meteor MongoDB instance runs on port 3002 with bind_address 127.0.0.1, and the data files are located in the Meteor .meteor/local/db project subdirectory.

See the documentation if you are not familiar with import / export in MongoDB.

+2
May 15 '12 at 3:01
source share

All I did was add the IP address of my digital drip server, not localhost, and it worked:

 env: { ROOT_URL: 'http://yourdomain.com', MONGO_URL: 'mongodb://104.236.24.66:27017/meteor', PORT: 3002, }, 



EDIT: Use MUP to deploy your meteor projects: https://github.com/zodern/meteor-up

 env: { ROOT_URL: 'https://www.example.com', MONGO_URL: 'mongodb://localhost/meteor', }, 

Mup uses Docker and will "bind" your 2 containers, thus placing both the application and mongo on the same virtual machine (server). For security reasons, your mongoDB should not be accessible from a public IP address.

0
Apr 15 '17 at 16:42 on
source share

You need to save the application in one terminal window, then open another and type โ€œmeteor mongoโ€, and it should work!

-5
Sep 07 '15 at 11:47
source share



All Articles