我想了解如何在 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 服务器应用程序之前,我需要设置环境变量.为此,您需要在调用meteor 或为在系统上运行meteor 应用程序的配置文件预设环境时在命令行上传递环境变量.
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:12345/' meteor您还应该确保 mongodb 可访问且您的用户凭据正确无误!我假设您正在尝试使用远程 mongodb 实例在本地机器上运行meteor.
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 上
您必须在meteor 应用程序文件夹中创建一个批处理文件来调用环境变量.这里有一个例子:stackoverflow/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: stackoverflow/a/29833177/1997579
更多推荐
如何在 Meteor 中连接到外部 MongoDB 实例?
发布评论