Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

SimpleSchema validation succeeds but on insert fails with keyNotInSchema fro SubSchema #367

Open WilliamT-Streamba opened 6 years ago

WilliamT-Streamba commented 6 years ago

I have a schema which references a sub schema.

When I validate the schema manually with SimpleSchema.validate it succeeds. However, when I try and insert the item it fails saying the keys of the sub schema are not valid.

The exact same code works in another project. The only difference is this is based off a package based architecture so the attachSchema code is inside a package that is imported into the project.

Any suggestions of where to look for the cause?

I've checked that the sub schema is part of the schema when it is attached to the collection.

aldeed commented 6 years ago

You would need to post a link to a simple app that reproduces this. Hard to say without seeing the whole setup.

janKir commented 6 years ago

I'm facing the same issue. In my case, it seems like a field (which itself is a nested SimpleSchema object) is wiped out during cleaning, and then the insert validation fails with Error: <field> is required in <collection> insert. Though, if I validate the object manually, the validation succeeds.