How to make an object with and server-only functions?


I can’t see how I have to modelize my application for server/client accessible object.

What I understand: is for the functions called from the client. For the functions only needed for the server, I can make a class object with all my methods inside.

But what happen to an object that have both?
For example I have a collection Notifications. I want the interface to be able to update a list of notification to a read state.

import { Mongo } from 'meteor/mongo';
export const Notifications = new Mongo.Collection('notifications');
    'notification.setAsRead': function(doc){

But I want to have a function to send notifications for the server part. So I can make

Notifications = class Notifications {
  constructor(doc) {

But the object Notification is already a Mongo Collection

:question: How can I deal with this problem? :question:
Thanks for your remarks. :thumbsup:


You can either define some static functions on the Notifications-Collection (I see that quite often)
and call that in the method:

Notifications.setAsRead = function(notificationId) {
   this.update(notificationId, {$set: {read: true}});


    'notification.setAsRead': function(notificationId){

Or you put these methods in another file like NotificationService or whatever, but it’s basically the same.


Hi macrozone!
Well it’s true that it is an object after all…
So I can add functions to a mongo object! This resolve my question!
I can add all those server functions in a server/ directory under the imports/api/notifications

But I will not be able to have a constructor. I can have a NotificationService for that…

Thanks :wink: