Meteor client synchronous server database calls


I am building an application in Meteor that relies on real time updates from the database. The way Meteor has laid out the examples is to have the database call under the Template call. I've found that when dealing with medium sized datasets this becomes impractical. I am trying to move the request to the server, and have the results passed back to the client.

I have looked at similar questions on SA but have found no immediate answers.

Here is my server side function:

    "getTest" : function() {
                   var res = Data.find({}, { sort : { time : -1 }, limit : 10 });
                   var r = res.fetch();
                   return (r);

And client side:

    Template.matches._matches = function() {
        var res= {};"getTest", function (error, result) {
            res = result;
        return res;

I have tried variations of the above code - returning in the callback function as one example. As far as I can tell, having a callback makes the function asynchronous, so it cannot be called onload (synchronously) and has to be invoked from the client.

I would like to pass all database queries server side to lighten the front end load. Is this possible in Meteor?


Problem courtesy of: kyleredon


The way to do this is to use subscriptions instead of remote method calls. See the counts-by-room example in the docs. So, for every database call you have a collection that exists client-side only. The server then decides the records in the collection using set and unset.

Solution courtesy of: Sjoerd Visscher


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.