2016-12-31 49 views
0

我剛剛創建了一個新項目。流星1.4 Aldeed Collection2未開箱即用

這是我加入到我的項目包:

aldeed:[email protected] 
aldeed:autoform 

我還安裝了NPM包,meteor npm install --save simpl-schema

我創建了一個/lib文件夾。

在這裏面,我創建了一個common.js文件與此代碼:

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); 

當我重新啓動應用程序,它崩潰,扔我:

=> 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 

任何想法有什麼不對?

+0

出於好奇,爲什麼安裝collection2通過流星添加,但通過npm簡單模式? collection2自動添加簡單模式。那麼[collection2-core](https://atmospherejs.com/aldeed/collection2-core)你有沒有'npm install' [這個簡單模式](https://www.npmjs.com/package/simple-schema )? –

+0

@MichelFloyd我通過'npm'按照Aldeed自己安裝'collection2-core @ 2.0.0'的指示安裝它。我也'npm install'簡單模式,但是同樣的錯誤出現。 – Neonjack

+0

你從哪裏找到這些說明?沒有提及npm [這裏](https://atmospherejs.com/aldeed/collection2-core) –

回答

0

試試這個....

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

另外,您還可以將模式爲:從NPM包SIMPL型模式使用時

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

SimpleSchema不被視爲一個全局變量。你必須確保:

import SimpleSchema from 'simpl-schema';