How do I use an existing MongoDB in a Meteor proje

2019-01-02 19:49发布

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

How could I connect my new Meteor project to my already existing MongoDB?

标签: meteor
7条回答
浮光初槿花落
2楼-- · 2019-01-02 20:17

You have to keep your app running in one terminal window then open another and type "meteor mongo" and it should work!

查看更多
春风洒进眼中
3楼-- · 2019-01-02 20:21

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.

查看更多
不流泪的眼
4楼-- · 2019-01-02 20:23

Just copy the data to the Meteor MongoDB database - no reason to try to hook Meteor up to the existing database and risk overwriting things.

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

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

查看更多
情到深处是孤独
5楼-- · 2019-01-02 20:28

All I did was add the IP of my Digital ocean droplet server, instead of 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 "link" your 2 containers, thus hosting both the app and mongo on the same VM (server). Your mongoDB shouldn't be accessible from the public IP for security reasons.

查看更多
冷夜・残月
6楼-- · 2019-01-02 20:30

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
查看更多
冷夜・残月
7楼-- · 2019-01-02 20:31

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.

查看更多
登录 后发表回答