Collection2 and audit-argument-checks


#1

I was using checks on my methods to validate before insert and update, and added the package audit-argument-checks to enforce the use of checks. Now I’m using Collections2 and I don’t know if I should continue using checks, due to the fact that Collection2 and SimpleSchema validate the data.

On my methods I’m using checks this way:

check(client, Clients.simpleSchema());

The problem is that on my schema I have a required field with a default value. If I insert directly without methods, Collection2 automatically create the field with the default value. But if I use methods, on the check line fail due to the fact that the required field doesn’t exist yet.


#2

You don’t need to use check if you are using Collection2 / SimpleSchema. All of this is handled through the collection and it will not let you insert bad data as long as you have your schemas properly defined. This works on both client and server so it works even if you are using Meteor methods.


#3

audit-argument-checks enforces validation of method arguments. Collection2 prevents inserting bad data into collections. Those are two different beasts.


#4

If you’re using methods to perform DB operations it’s still worth validating your method arguments as well as enforcing a schema for the DB. Who knows what sort of error could happen from bad arguments before you even attempt the DB operation.


#5

If you’re doing everything via meteor methods why use collection2 isn’t simple schema all you need? what value is there for all having collection2


#6

Collection2 does the check automatically for you. You don’t have to worry about forgetting to check some arguments and your code is more compact.