[SOLVED] Easy-search package and subscribe/publish + limit

For my app I implemented the pagination using publish/subscribe with limit/skip. I also need the option to search for items, and for that task I am using matteodem:easy-search with the MongoDB searcher.

In my collection for each item I have:
id:
title:
description:
location:

I show let’s say 10 items, and when the user click on item’s title the complete item is shown (description, location, …) in a new page, using iron-router.

Now the problem: If I am searching after let’s say the title of one item, easy search will find the item and will show the results from mongodb collection, but when I click on that found item, of course sometimes, the description, location, … parts are missing because the item is not fetched yet in minimongo on client, maybe is not in the “LIMIT” items which are already on client.

So, any solution or advice for that?

Thanks a lot.

With the _id of that item, when you click to go to the route of that item

waitOn: function () { subscribe('item', _id); }

And on your server

publish('item', function (id) {
   return collections.item.findOne(id);
});

In summary, subscribe to a new publish that will return the specific item you are viewing separate from your search results. Going off discover meteor and the meteor docs, minimongo will merge same items so when you do collections.item.findOne(id) on the client side, it will be the one unique item but have all the fields now or what you published on the server.

Thanks a lot. I got the idea. But, it seems that I should use:

    Meteor.publish('item', function (id) {
         return Collection.find({_id: id});
    });

because findOne does not return a Mongo cursor. It returns a Mongo document and I got:

Exception from sub item id Y7fFmKRTrkjfDWCBZ Error: Publish function can only return a Cursor or an array of Cursors

Yep, that’s correct.

If this solves your question, please edit your question to put [SOLVED] in front, helps people like me make answering questions easier.