Meteor.js 连接到但不发布到远程 mongo 服务器?

Meteor.js connects to, but does not publish to, remote mongo server?

所以我通过包含 MONGO_URL::@: 的推荐方法将 meteor 的开发模式实例连接到远程 mongo,以便拥有用于保存用户状态的持久集合将允许用户稍后通过将他们输入的内容加载到应用程序中来返回。我可以在 mongo 服务器上看到来自 meteor 服务器的几个连接。

但是,当 运行 运行该应用程序时,mongo 服务器上不会出现任何集合。 "Show Collections" 和 db.getCollections() return 都没有。

如果我在没有远程连接的情况下终止应用程序进程并再次 运行 meteor,则集合在 meteor 启动的 mongo 实例中显示得很好。

我需要在代码中使用 meteor 做一些特别的事情才能将集合正确推送到远程实例吗? (即关闭自动发布)

当你在本地开发时mongo shell你通常输入meteor mongo并且shell已经进入了你的流星环境的默认数据库。

在您的服务器上,您首先需要明确输入要使用的数据库:

use <db_name>
db.getCollections()

您要使用 MONGO_URL 定位的数据库也需要按以下模式定义:

MONGO_URL=mongodb://<db_username>:<db_password>@<db_server_host>:<db_server_port>/<db_name>

确保在使用 use 命令连接和输入数据库时​​为 db_name 使用相同的值。

资源:

https://galaxy-guide.meteor.com/environment-variables.html

https://docs.mongodb.com/manual/core/databases-and-collections/