I have a MongoDB collection for chat messages. With every chat message, the user's id is stored. When I publish the collection to the client, I want to replace each user's id with their useame, but in the server's version of the collection I need to keep the user's id because I want to allow the user to change their name etc. My current solution is to publish the users collection to the client, and let the client replace ID with name using a registerHelper. While this works with smaller projects, I would not want to send 2000 users to the client just so they can replace ID with names.
This is the data stored in each chat message when it is sent.
chatroomMessages.insert({
text: msg,
from: Meteor.userId(),
date: Date.now(),
room: findChatroom._id
});
Here is the current id to name function, if it is of any use.
Template.registerHelper('idToName', function(id) {
if (users.findOne({_id:id}) != null) {
retu users.findOne({_id:id}).useame;
}
});
