Here is an example of how you can set up something like this:
File: collections/system.js
this.System = new Meteor.Collection('system');
Meteor.methods({
pageViewInc: function() {
System.update({ config: true }, { $inc: { 'stats.pageviews': 1 } });
}
});
if (Meteor.isServer) {
const isSystemExists = System.findOne({ config: true });
if (!isSystemExists) {
const options = {
stats: {
pageviews: 0
},
config: true
};
System.insert(options);
}
}
You can then create a function to call the 'pageViewInc' method using Meteor.call.
If you are using Meteor-Iron-Router, you can make the call in the 'after' callback.
Meteor.call('pageViewInc');
You can create similar methods for the Posts Collection or utilize the meteor-collection-hooks package which has an 'after findOne' hook that can be implemented on the server side.