Best way to store messages in meteor chat app

Hi guys!

First I want to thank the community for supporting this wonderful project!

Question:

How do you think is better way to store messages in the meteor application?
What methods and techniques do you apply?

Thanks!

Hey @robinbobin - A simple collection with a publication/subscription would do the trick. Your schema could look something like:

{
  createdDate: { type: Date },
  userId: { type: String },
  message: { type: String }
}

And publication:

Meteor.publish('messages', function () {
  return Messages.find();
});

That with a simple method to add messages would do it.

1 Like

Thanks for you reply!

Don’t forget to include ownership and privacy checking. For example, we don’t have userId but userIds (plural) as an array. During publication we check that userIds contains this.userId. If you have hierarchy levels, it can get more complicated, but for a simple chat app that should be enough.

3 Likes

Look at RocketChat, it’s an open source Slack competitor built with Meteor. At that scale subscriptions aren’t really an option so they use their DDP Streamer package to send events without tailing the op log

1 Like

You might also check out my Messaging package. It does all the hard work, you just attach the interface.

As mentioned any chat that relies on mongo’s oplog is going to eventually have scaling issues. To solve this I’m working to integrate redis-oplog into the next version and implement conversation specifc update channels. After that scaling should not be an issue.

Also just in case they might be helpful, I’ll mention that there are a whole host of packages in the Socialize namespace (with even more on the way) that implement social networking type features.

3 Likes