ValidatedMethod and Mongo Cursors

I’m not sure why this code does or does not work:

export const EntitySearchSchema = new SimpleSchema({
	searchLimit: {type: Number}

export const listEntities = new ValidatedMethod({
	name: 'entities.list',
  validate: EntitySearchSchema.validator(),
  run(searchLimit) {
		if (Meteor.isServer) {
      return {count: Entities.find({}, { limit: searchLimit }).count();};

This results in: Exception while invoking method 'entities.list' Error: Match error: Failed Match.OneOf, Match.Maybe or Match.Optional validation from the server, and a fantastically unhelpful client-side error, ending with:

{... isClientSafe: true, error: 400, reason: "Match failed", details: undefined, message: "Match failed [400]", errorType: "Meteor.Error" }

After many hours of trial-and-error, I found that changing:

return {results: Entities.find({}, { limit: searchLimit }).fetch();};


return {results: Entities.findOne('someRandomId'};

returns things just fine.

The call-site is inside a component:'entities.list',
        searchLimit: 5
      function (error, res){
        if (error) {
        } else {

I am honestly at a loss as to why the first fails and the second one works. I know that the first is using a cursor… is there a way to force it to resolve and return the data so this [400] Match error stops appearing?

Publications would be nice, but there are too many rows to load client-side, so server-side loading is preferable.


Change the signature of run to:

run ({ searchLimit })
1 Like