fardeem
fardeem

Reputation: 594

How to test for collection ID in Meteorjs

Several of my methods take in IDs as input. I was wondering how could I use the check package to check if these were valid ids or not. It seems Meteor doesn't use the conventions defined in the Mongo docs.

Upvotes: 2

Views: 52

Answers (1)

henkimon
henkimon

Reputation: 1481

From the Mongo.Collection documentation we see that upon creating it takes an option idGeneration which is used to determine the method of generating the _id fields of new documents. The default method is a random string, meaning that you should use check(docId, String).

The other method is using random Mongo.ObjectID values. For this method you can use Match.Where(<function>) to determine that the id is valid with a simple regex.

Upvotes: 1

Related Questions