如何在Meteor中连接到外部MongoDB实例? [英] How to connect to external MongoDB instance in Meteor?
问题描述
我想了解如何连接到Meteor中的外部MongoDB实例.
I would like to find out how to connect to an external MongoDB instance in Meteor.
我已添加此环境
Meteor.startup(function () {
process.env.MONGO_URL = 'mongodb://[UN]:PW]@[host]:[port]/meteorTest'
});
,但是数据仍然来自本地数据库.
but still the data is coming from the local database.
我想将所有集合从我的本地数据库移到该外部数据库.我阅读了所有教程,所有内容都告诉我设置该evn变量,但实际上没有任何作用.如何测试其是否已连接?
I want to move all the collections from my local db to this external db. I read all the tutorials, its all telling me to setup this evn variable but nothing really working. How do I test whether its connected or not?
推荐答案
以我自己的经验;在启动meteorjs服务器应用程序之前,我需要设置环境变量.为此,您需要在调用流星时在命令行上传递环境变量,或者为在系统上运行流星应用程序的配置文件预置环境.
In my own experience; I have needed to set the environment variable before starting the meteorjs server app. To do this you will need to pass the environment variable on the command-line as you invoke meteor or preset the environment for the profile that is running the meteor app on your system.
因此,您将使用以下命令启动应用程序:
So you would start your app with this kind of a command:
MONGO_URL='mongodb://user:password@remote.domain.com:12345/' meteor
您还应该确保mongodb可以访问并且您的用户凭据正确!我假设您正在尝试使用远程mongodb实例在本地计算机上运行流星.
You should also make sure that the mongodb is reachable and that your user credentials are correct! I am assuming you are trying to run meteor on your local machine using a remote mongodb instance.
在Windows上
您将必须在流星应用程序文件夹中创建一个批处理文件以调用环境变量.这里有一个例子: https://stackoverflow.com/a/29833177/1997579
You will have to create a batch file in your meteor application folder to invoke the environment variable. There is an example of this here: https://stackoverflow.com/a/29833177/1997579
这篇关于如何在Meteor中连接到外部MongoDB实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!