A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
In my project, v3.2.0 introduced a breaking change. That's either a bug in meteor-collection2 or I've used extending schemas in an unintended way. In any case, this could break existing projects and should be fixed or documented.
To Reproduce
The following code yields different results in v3.1.0 and v3.2.0
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
const MyCollection = new Mongo.Collection('myCollection');
const mySchema = new SimpleSchema({
foo: { type: String },
});
MyCollection.attachSchema(mySchema);
MyCollection.insert({ foo: 'foo' });
mySchema.extend({
bar: { type: String, optional: true },
});
// I'm expecting that the `bar` key is set. It isn't in v3.2.0.
MyCollection.update({ foo: 'foo' }, { $set: { foo: 'foo', bar: 'bar' } });
// Logs { _id, foo, bar } in v3.1.0
// Logs { _id, foo } in v3.2.0
console.log(MyCollection.findOne({ foo: 'foo' }));
Expected behavior
Both versions should work the same.
Versions (please complete the following information):
Meteor version: 1.11.1
Version: 3.1.0 vs. 3.2.0
Additional context
From what I read about Attaching Multiple Schemas to the Same Collection (introduced in v3.2.0), I will now use MyCollection.attachSchema(extension) instead of mySchema.extend(extension). IMO the second would be more explicit.
Describe the bug
In my project, v3.2.0 introduced a breaking change. That's either a bug in
meteor-collection2
or I've used extending schemas in an unintended way. In any case, this could break existing projects and should be fixed or documented.To Reproduce
The following code yields different results in v3.1.0 and v3.2.0
Expected behavior
Both versions should work the same.
Versions (please complete the following information):
Additional context From what I read about Attaching Multiple Schemas to the Same Collection (introduced in v3.2.0), I will now use
MyCollection.attachSchema(extension)
instead ofmySchema.extend(extension)
. IMO the second would be more explicit.