Wes
Wes

Reputation: 844

In Meteor, when publishing a search result with a limit, why does a ".count" on the result show more than the limit?

I'm publishing a search result and I'm limiting the results to 500:

 Meteor.publish("myPublish", function (status) {
    var foundOnServer = MyCollection.find({"status": status}, {limit: 500, sort: {"someField": 1}});
    console.log("returning " + foundOnServer.count() + " documents from server");
    return foundOnServer;

  });

But when the query would result in more than 500 documents, the console.log shows the actual number (more than 500), but on the client, I only get the 500 documents. So, it seems as if it is being properly limited, but I don't understand why the console would report the actual number of documents, ignoring the limit.

Upvotes: 3

Views: 111

Answers (1)

Wes
Wes

Reputation: 844

Thanks to @Curtis this is a known issue: https://github.com/meteor/meteor/issues/1503

So, if you want to "prove" to yourself with a console.log that you got the number of records you asked for, you should instead do:

console.log("returning " + foundOnServer.fetch().length + " documents from server");

but it also might be interesting to log the result of .count as well, as it will show when the query is getting more than the limit.

Upvotes: 1

Related Questions