Search code examples
simple-schemaangular2-meteor

Cannot find attachSchema property on Mongo.Collection with angular2-meteor


Here is my problem :

I want to use the power of simple-schema to be able to check my inserts against the following schema :

let UprocSchema = new SimpleSchema({
    "name": { type : String, label: "Nom Uproc" },
    "label": { type : String, label: "Libellé Uproc" },
    "status": { type : String, label: "Status UPR" }
});

For some reason I ignore, even if the SimpleSchema seems to be well instanciated, I cannot use the attachSchema property on Mongo.Collection.

Here is my code :

let repo_collection = new Mongo.Collection('repository');
export const Repository = new MongoObservable.Collection<Uproc>('repo_collection');
repo_collection.attachSchema( UprocSchema );

Here is my error messages :

Property 'attachSchema' does not exist on type 'Collection<{}>'.

TypeError: repo_collection.attachSchema is not a function


Solution

  • attachSchema is part of [collection2][1] package.

    Documentation states:

    Create one or more SimpleSchema instances and then use them to validate objects. By adding the aldeed:collection2 package to your app, you can attach them to collections to get automatic validation of your insert and update operations.