Meteor 1.4 Aldeed Collection2 not working out of the box

667 views Asked by At

I just created a fresh project.

These are the packages I added to my project:

aldeed:[email protected]
aldeed:autoform

I also installed the npm package, meteor npm install --save simpl-schema.

I created a /lib folder.

In it, I created a common.js file with this code:

var Books = new Mongo.Collection("books");

var Schemas = {};

Schemas.Book = new SimpleSchema({
    title: {
        type: String,
        label: "Title",
        max: 200
    },
    author: {
        type: String,
        label: "Author"
    },
    copies: {
        type: SimpleSchema.Integer,
        label: "Number of copies",
        min: 0
    },
    lastCheckedOut: {
        type: Date,
        label: "Last date this book was checked out",
        optional: true
    },
    summary: {
        type: String,
        label: "Brief summary",
        optional: true,
        max: 1000
    }
});

Books.attachSchema(Schemas.Book);

As soon as I restart the app, it crashes, throwing me this:

=> Exited with code: 1
W20161231-01:03:28.126(-5)? (STDERR) /home/mehdi/.meteor/packages/meteor-tool/.1.4.2_3.17tso1e++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
W20161231-01:03:28.127(-5)? (STDERR)                        throw(ex);
W20161231-01:03:28.127(-5)? (STDERR)                        ^
W20161231-01:03:28.127(-5)? (STDERR) 
W20161231-01:03:28.127(-5)? (STDERR) TypeError: Cannot read property 'definitions' of undefined
W20161231-01:03:28.127(-5)? (STDERR)     at /home/mehdi/workspace/collection/node_modules/simpl-schema/dist/SimpleSchema.js:778:39
W20161231-01:03:28.128(-5)? (STDERR)     at Function._.each._.forEach (/home/mehdi/workspace/collection/node_modules/underscore/underscore.js:158:9)
W20161231-01:03:28.128(-5)? (STDERR)     at checkSchemaOverlap (/home/mehdi/workspace/collection/node_modules/simpl-schema/dist/SimpleSchema.js:777:24)
W20161231-01:03:28.128(-5)? (STDERR)     at SimpleSchema.extend (/home/mehdi/workspace/collection/node_modules/simpl-schema/dist/SimpleSchema.js:407:7)
W20161231-01:03:28.128(-5)? (STDERR)     at new SimpleSchema (/home/mehdi/workspace/collection/node_modules/simpl-schema/dist/SimpleSchema.js:96:10)
W20161231-01:03:28.128(-5)? (STDERR)     at [object Object].c2AttachSchema [as attachSchema] (packages/aldeed:collection2-core/collection2.js:35:10)
W20161231-01:03:28.128(-5)? (STDERR)     at meteorInstall.lib.common.js (lib/common.js:33:7)
W20161231-01:03:28.128(-5)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:181:9)
W20161231-01:03:28.128(-5)? (STDERR)     at require (packages/modules-runtime.js:106:16)
W20161231-01:03:28.129(-5)? (STDERR)     at /home/mehdi/workspace/collection/.meteor/local/build/programs/server/app/app.js:60:1

Any idea what's wrong?

3

There are 3 answers

0
ERWilliams On BEST ANSWER

Try this ....

var Books = new Mongo.Collection("books");

Books.schema = new SimpleSchema({
    title: {
        type: String,
        label: "Title",
        max: 200
    },
    author: {
        type: String,
        label: "Author"
    },
    copies: {
        type: SimpleSchema.Integer,
        label: "Number of copies",
        min: 0
    },
    lastCheckedOut: {
        type: Date,
        label: "Last date this book was checked out",
        optional: true
    },
    summary: {
        type: String,
        label: "Brief summary",
        optional: true,
        max: 1000
    }
});

Books.attachSchema(Books.schema);
0
Joost Döbken On

Alternatively you can also attach the schema as:

const Books = new Mongo.Collection("books");
Books.attachSchema(new SimpleSchema({
  title: {
    type: String,
    label: "Title",
    max: 200
  },
  ...
}));
0
Taslack On

SimpleSchema is not considered a global variable when used from the NPM package simpl-schema. You have to make sure to:

import SimpleSchema from 'simpl-schema';