Meteor MongoDB Fetch Progressive

When I run a .fetch() command, it first returns null, then say suppose I have 100 documents and it will keep on loading from 1 to 100 and the counter keeps updating from 1 to 100 progressively. I don’t want that to happen. I want all the results to be displayed at once after the fetch process has been completed.

Also, how can I display a relevant message to the user if no documents exist? The fetch method doesn’t work for me since it returns 0 at first and hence “No document found” flashes for a second.

This is just a wild guess, but I suppose you’re operating on the client side and your subscription is not ready yet. Therefore you get zero documents when calling .fetch().

The trick is to call .fetch() only after your subscription is ready.

How to check if the subscription is ready…

This is my server side code…

Meteor.publish("challenge-taken", function (userID) {
  return databaseName.find({userID:userID});

Here’s some relevant help from the Meteor guide. I highly recommend looking up things from the guide, it has a search and all: Publications and Data Loading | Meteor Guide

…and here’s the method signature for Meteor.subscribe: