Reputation: 2113
Is there a way with simple schema in meteor to tell what the type of the different fields are? I know that I can type the following to get the schema:
Answers.simpleSchema().schema()
This will give me an object of all the fields. Say I have a field called "image" which is a string- there is a key in the image object called "type" which is a function:
function String() { [native code] }
The function type does change to Number() as I'd expect, when I try to type Answers.simpleSchema().schema().image.type() though, it comes back empty. Is there a better way to determine the field type for all of my fields in my schema? I need to do convert field inputs to strings vs numbers as appropriate and this seems the best way to do it. Thanks!
Upvotes: 0
Views: 410
Reputation: 20226
You can use simple-schema's clean method to automatically do type conversions (ex: string to integer) saving you potentially a lot of code.
mySchema.clean(obj)
Upvotes: 1