Collection2 auto "clean" not working

Hi, I am trying to split the codebase of the application into several Meteor packages. I am moving all the collections and schemas from the application repository into their own repository. Let’s call the repositories: repo-app and repo-model.
So collections, schemas, and some methods are moved from repo-app to repo-model.

The issue
The problem is that when Collection.update(id, modifier) is called in a method that is imported from repo-model it does not auto clean the modifier against the schema, i.e. defaultValues are not set automatically.

Note from aldeed:simple-schema: The Collection2 package always calls clean before every insert, update, or upsert.

The problem does not happen if the method is not imported from repo-model and is called directly from repo-app.

Some information
The insert and update on all collections are extended to add additional information about the query. Like updatedBy and updatedAt etc.

class Collection extends Mongo.Collection {
  insert(doc, options, callback) {
    // code that extends doc
    return super.insert(doc, options, callback)
  update(selector, modifier, options, callback) {
    // code that extends the modifier
    return super.update(selector, modifier, options, callback)

The packages used


I don’t think I could say why this is happening without some sort of reproduction for use in debugging.

That being said, if you believe that extending the collections for fields like updatedAt and updatedBy could be affecting this, then you might try moving this functionality into autoValue’s in the SimpleSchema for each collection. You could even just create this as a separate SimpleSchema and attach this schema along with the original and both will be merged for the collection.

new SimpleSchema({
  createdAt: {
    type: Date,
    autoValue () {
      if (this.isInsert) {
        return new Date();
      return undefined;
    index: -1,
    denyUpdate: true,
  updatedAt: {
    type: Date,
    autoValue () {
    optional: true,
    index: -1,
  updatedBy: {
    type: String,
    regEx: SimpleSchema.RegEx.Id,
    autoValue () {
        return this.userId;
    index: 1,
    denyUpdate: true,

Let me come back to you with something that can be reproduced.

Though I have tried removing extensions - it didn’t make a difference. I was just trying to provide additional information on the setup of collections.

The main problem is that simple-schema refuses to clean the document automatically before update.
The only workaround I see at the moment is to call Shema.clean(doc) manually when required.
It’s annoying though and not so easy in my case.

Yes, reproduction would be optimal. This should definitely work because I use SimpleSchema and Collection2 with auto values in all of my Socialize packages and everything works perfectly AFAIK.