Best way and perfomance

#1

I was creating a new component on my app on which I need to display tags while the user is typing them (the best example here is when we’re creating a post on Stackoverflow and we’re adding these tags).

This collection has tagTitles, userId (this is not sending to user) and counts. Quite simple.

Now I saw 2 different ways to archive this:

A. Subscribe to everything and find the tags that we want
Meteor.subscribe('tags'); // executes just once at beginning
and
Tags.find({tagName: 'tag-name'}); // executes every time we want to find tags

B. Subscribe just to what we’re looking for

// executes every time we want to find tags
Meteor.subscribe('food', () => [{
             limit: 21
         }, 'tag-name'
         ], function (err) {
             if (!err) {
                 Tags.find();
             }
         });

The problem that I found with option B is that the callback doesn’t work properly. It’s too fast and you have to move the find() inside an autorun()

This is regarding to one post I saw recommending the using of find()[0] instead find() because the result is “much” faster.

What do you think guys, which approach is more efficient and faster?

#2

So what does find()[0] do? Just returns undefined for me…

#3

are you using fetch()? You need to convert the result from the cursor to an array.
See first comment: [SOLVED] Fetching value of one field with a specific id

So regarding with these option do you think we can get an improvement using the option B?