如何在 Meteor 中连接到外部 MongoDB 实例?

编程入门 行业动态 更新时间:2024-10-14 08:23:47
本文介绍了如何在 Meteor 中连接到外部 MongoDB 实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想了解如何在 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 实例?

本文发布于:2023-11-25 20:39:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631271.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   实例   如何在   Meteor   MongoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!