I’m trying to setup my first Meteor 3 app using SimpleSchema, Collection2, indexes and TypeScript. First off, thanks to the community for porting these important packages! However, I got a bit confused about how to setup this correctly.
The docs of aldeed:simple-schema
say you should use version 2.0.0
or higher, but there’s only a 1.13.1
available. I picked this version, and it seems to work.
The docs of aldeed:collection2
say you should either initialize it using
import 'meteor/aldeed:collection2/static';
or
import 'meteor/aldeed:collection2/dynamic';
Collection2.load();
But they don’t state where to put this code.
I added the static version to a common.js
file and this made Meteor find Mongo.Collection.attachSchema()
, so I guess this was the right approach. However, TypeScript still complains about the missing method attachSchema()
. Is there a way to get rid of this error?
If I try the “dynamic” approach, Meteor starts complaining about the missing method again. Maybe because attachSchema()
is being called before Collection2.load()
is ready. Should I place all schema attachments in a Meteor.startup()
then? Also, calling a global Collection2
variable seems a bit odd to me.
The indexing feature seems to work right away, which is amazing.
However, I still have an issue with autoValues like these:
createdAt: {
type: Date,
optional: true,
index: 1,
autoValue: function() {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return {
$setOnInsert: new Date()
};
} else {
this.unset();
}
}
},
TypeScript complains that this.insert
, this.upsert
and this.unset
are not valid. According to the docs, they should work fine. Maybe just the TypeScript notations are missing here?