Checking the Meteor.call array parameter

I execute Meteor.call('searchDatabase', keys...) , which is executed whenever the user submits a request. I am currently passing an array of words represented under the name keys . However, I do not know how to do the necessary check(keys, ?) On the server side. Initially, I thought I could do keys.forEach(function(element) { check(element, String)} , but I still get the Did not check() all arguments error. Should I just pass the sent search as the source string to Meteor method method and then split it on the server? or is there a way to verify that the keys are an array?

+5
source share
3 answers

If keys is an array of strings, you can simply do:

 check(keys, [String]); 

Your method will look something like this:

 Meteor.methods({ searchDatabase: function(keys) { check(keys, [String]); // add other method code here } }) 
+13
source

As shown here: https://forums.meteor.com/t/check-object-in-an-array/3355

 var subscriptions = [ {/* ... */}, {/* ... */}, {/* ... */} ]; check(subscriptions, Match.Where(function(subscriptions){ _.each(subscriptions, function (doc) { /* do your checks and return false if there is a problem */ }); // return true if there is no problem return true; })); 
0
source

If you are using simple-schema , you should try as follows:

 check( keys, [ mySchema ] ); 

You can learn more about validation patterns in this link using-the-check-package

0
source

All Articles