无法在Meteor App中连接到备用Mongo DB [英] Cannot connect to alternate Mongo DB in Meteor App

查看:82
本文介绍了无法在Meteor App中连接到备用Mongo DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Meteor应用程序.在本地使用虚拟机(VM).我想使用我在VM上设置的名为"my_db"的新Mongo数据库.我已经在命令行上设置了MONGO_URL,如下所示:

I am running a Meteor app. locally using a Virtual Machine (VM). I want to use a new Mongo DB that I have set-up on the VM called 'my_db'. I have set the MONGO_URL on the command line like this:

export MONGO_URL='mongodb://127.0.0.1:3001/my-db'

我检查了是否使用echo $ MONGO_URL设置了此环境变量,然后返回:

I have checked that this environment variable is set using echo $MONGO_URL and I get back:

mongodb://127.0.0.1:3001/my-db

但是,当我启动Meteor应用程序时.它仍然连接到默认的流星"数据库.为什么会这样,我该怎么做才能使其连接到我的备用"my_db"数据库?

However, when I start up my Meteor app. it still connects to the default 'meteor' database. Why is this and what can I do to get it connecting to my alternative 'my_db' database?

推荐答案

就像@ dr.dimitr说env vars仅在生产过程中使用(例如,将您的模数应用程序与它们提供的模数db连接或使用其他模数) ,在开发过程中,您可以像这样使用mongo驱动器.

Like @dr.dimitr say env vars are only used on the production process (for example connecting your modulus app with the modulus db they provide or another different), on the developing process you can use the mongo drive like this.

if(Meteor.isServer){
    Meteor.startup(function () {
       var myDatabase = new MongoInternals.RemoteCollectionDriver("<mongo url>");
       MyCollection = new Mongo.Collection("collection_name", { _driver: myDatabase });
     });
   }

现在您需要知道URL <mongo url>的名称,该名称可能类似于mongodb://127.0.0.1:27017/localmeteor

Now you need to know name of the url <mongo url> which could be something like mongodb://127.0.0.1:27017/local or meteor

一些相关帖子-(1)(2)

这篇关于无法在Meteor App中连接到备用Mongo DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆