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

Upsert no longer works in 3.0.5 #408

Closed rijk closed 4 years ago

rijk commented 4 years ago

The change done for #403 seems to break an existing upsert, that works in 3.0.4:

Tags.upsert(
  { 
    "color": "orange", 
    "label": "Today", 
    "team": {
      "id": "jPrbLLC8mMQcMe6ZC",
      "slug": "myteam"
    }
  },
  {
    "$set": {
      "lastUsedAt": new Date
    }
  }
)

In 3.0.5 gives the following error: Error: Team is required in tags update

I20200107-20:20:52.143(1)?   invalidKeys: 
I20200107-20:20:52.144(1)?    [ { name: 'team', type: 'required', value: undefined },
I20200107-20:20:52.144(1)?      { name: 'team.id', type: 'required', value: undefined },
I20200107-20:20:52.144(1)?      { name: 'team.slug', type: 'required', value: undefined } ],

This is the schema:

Tags.attachSchema(new SimpleSchema({
  team: {
    type: new SimpleSchema({
      id: {
        type: String
      },
      slug: {
        type: String
      }
    })
  },
  color: {
    type: String
  },
  label: {
    type: String
  },
  lastUsedAt: {
    type: Date
  }
}))