Essentially, this is what I had in mind :
Client
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" });
Server
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
});
The client, I assume, uses minimongo, which is fine, but the server does not have access to a MongoDB instance whatsoever.
What would be the implementation on the server?
As mentioned in comments, I think this can be achieved using the manual publication methods described in the documentation. Something like this might work:
One thing to verify is whether
thisin thepublishfunction changes per client, in which caseroomsshould contain arrays, or whether it is the same object for all clients, as assumed here. But hopefully this point you in the right direction.