Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In a shared area:</p> <pre><code>function getSearchUsers(query) { var re = new RegExp(query, "i"); return Users.find({name: {$regex: re}}); } function getFriendUsers() { return Users.find({friend: true}); // or however you want this to work } </code></pre> <p>On the server:</p> <pre><code>Meteor.publish("searchUsers", getSearchUsers); Meteor.publish("friendUsers", getFriendUsers); </code></pre> <p>On the client:</p> <pre><code>Template.search.onCreated(function () { var self = this; self.autorun(function () { self.subscribe("searchUsers", Session.get("searchQuery")); }); }); Template.friends.onCreated(function () { this.subscribe("friendUsers"); }); Template.search.helpers({ searchResults: function () { return getSearchUsers(Session.get("searchQuery")); } }); Template.friends.helpers({ results: function () { return getFriendUsers(); } }); </code></pre> <p>The key takeaway from this is that what happens behind the scenes when the data is getting transferred over the wire isn't obvious. Meteor appears to <em>combine</em> the records that were matched in the various queries on the server and send this down to the client. It's then up the client to run the same query again to split them apart.</p> <p>For example, say you have 20 records in a server-side collection. You then have two publishes: the first matches 5 records, the second matches 6, of which 2 are the same. Meteor will send down 9 records. On the client, you then run the exact same queries you performed on the server and you should end up with 5 and 6 records respectively.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload