It depends on whether you need this to update the data reactively (which I think is not the best idea), or not. If reactivity is not important you can just use a server method, so
Meteor.methods({
'nbPosts': function () {
return Posts.find().count();
},
});
If you need reactivity you can implement a custom publish
method, just like in this example. Just keep in mind that this will be a lot more expensive in terms of server usage, and so a much less efficient.