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

Still have problem with multiple attach schema??? #373

Closed thearabbit closed 1 year ago

thearabbit commented 6 years ago

Excuse me, I still have problem with multiple attach schema (I would like to create collection behaviours)

// Soft Remove
CollectionExtensions.addPrototype('softRemove', function(selector = {}) {
  let self = this
  const schema = new SimpleSchema({
    removed: {
      type: Boolean,
    },
    removedAt: {
      type: Date,
    },
    removedBy: {
      type: String,
    },
  })
  self.attachSchema(schema, {selector: {type: 'softRemove'}});

  return self.direct.update(
    selector,
    {
      $set: {
        removed: true,
        removedAt: new Date(),
        removedBy: Meteor.userId(),
      },
    },
    {
      multi: true,
      selector: {type: 'softRemove'}
    },
    (error, result) => {
      if (result) {
        console.log('soft-remove')
      }
    }
  )
})

But have problem when I update collection, It is required soft remove field Please help me

aldeed commented 6 years ago

This should work. You would need to post the full error you get or a full reproduction

StorytellerCZ commented 1 year ago

Closing due to lack of reproduction.