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

[3.0.3] Upsert throws error if query has undefined value #400

Closed dovydaskukalis closed 4 years ago

dovydaskukalis commented 4 years ago

Code below will throw error Cannot convert undefined or null to object because of this line, https://github.com/Meteor-Community-Packages/meteor-collection2/blob/ebc48e2f164e0be73b699a951f48ffef108b2f33/package/collection2/lib.js#L10.

Collection.update(
    {
      key: 'value',
      anotherKey: undefined
    },
    {
      $setOnInsert: {
        createdAt: new Date()
      },
      $set: {
        a: 'b'
      }
    },
    {
      upsert: true
    }
  );
SimonSimCity commented 4 years ago

Doesn't this yield for everything that is not a string, including null and instances of Date?

dovydaskukalis commented 4 years ago

Only if the value is undefined or null. Other types such as Date, Number etc simply return [] which is fine.