【发布时间】:2021-06-08 12:34:09
【问题描述】:
基本上,这就是我的想法:
客户
const Messages = new Mongo.Collection("messages");
Meteor.call("message", { room: "foo", message: "Hello world");
Meteor.subsribe("messages", "foo");
// elsewhere
const messages = Messages.find({ room: "foo" });
服务器
Meteor.methods({
message: ({ room, message }) => {
// 1. remove old messages in the room
// 2. add new message to the room
}
});
Meteor.publish("messages", function (room) {
// 1. return message collection for room
});
我假设客户端使用minimongo,这很好,但服务器无权访问 MongoDB 实例。
服务器上的实现是什么?
【问题讨论】:
-
这可以按照文档中复杂的
publish示例,手动调用this.added等来完成。但是如果您尝试在没有mongo 连接的情况下启动它,流星不会抱怨吗?你是否已经以某种方式克服了这个问题? -
@ChristianFritz 不,meteor 不会抱怨缺少 MongoDB。我不记得我到底做了什么,但一切都在本地部署得很好。
-
你为
MONGO_URL设置了什么? -
@ChristianFritz 什么都没有。只有两个环境变量:
PORT和ROOT_URL。自去年 11 月以来,该应用程序一直在生产中不间断地运行,没有任何抱怨(空日志)。我知道我做了一些准备该应用程序的工作,因此不需要 MongoDB,但我不记得是什么。从那时起,我一直在从事许多项目。关键是,我需要添加这个功能:)
标签: javascript meteor ddp