2

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

paulpdaniels
  • 18,395
  • 2
  • 51
  • 55
Ronald Pauffert
  • 4,346
  • 1
  • 14
  • 15

1 Answers1

9

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.

blueren
  • 2,730
  • 4
  • 30
  • 47
  • the thing is that I cannot find any solution to install aldeed:collection2 on angular-meteor since there's no typings for this package, so I'm stuck with simple schema – Ronald Pauffert Nov 16 '16 at 12:50
  • Are you using any package for ```angular-meteor```? Also, is there any specific reason why you're attaching the schema to the collection? I believe it should work even withour that statement. The only change is that you must enforce the check schema on the server side as well. – blueren Nov 16 '16 at 13:02
  • I attach the schema to the collection because I want to be able to constraint the insert with unique value checking, and also to have auto-value inserts. – Ronald Pauffert Nov 16 '16 at 18:02