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

Selector provided in update is ignored #363

Closed nidem closed 6 years ago

nidem commented 7 years ago

Here is the example code from the README

Products.attachSchema(SimpleProductSchema, {selector: {type: 'simple'}});
Products.attachSchema(VariantProductSchema, {selector: {type: 'variant'}});

I have similar code where the schema is based on the based the type. This works:

Settings.update _id: doc._id,
    $set: 
        value: not doc.value
        type: 'Boolean'

The above works when I specify the type to the selector is used. However, when do not specify a type in the update I get an error.

Exception while invoking method '/settings/update' TypeError: Cannot read property 'clean' of null

I've tried the following (I believe I'm following the instructions too):

Settings.update _id: doc._id,
    $set: 
        value: not doc.value
,
    selector: type: 'Boolean'

To tell collections2 to use the selector type of Boolean, but I get an error.

Ultimately, I'm trying to perform an update on a field that is dependent on the scheme selected.

Note: the above is in coffeescript

aldeed commented 6 years ago

Closing old issues. Please comment if this is still an issue and should be reopened.