我正在通過Discover Meteor教程開展工作,儘管Posts = new Mongo.Collection('posts');
的所有功能都在服務器端Mongo shell上工作,但在瀏覽器控制檯上調用Posts功能很簡單不工作:Meteor 1.0 MiniMongo不向客戶端提供對象
Posts.insert()
ReferenceError: Posts is not defined`
收集在一個posts.js
我的文件夾lib/collections
宣佈,因爲這樣的:
Posts = new Mongo.Collection('posts');
if (Meteor.isServer) {
Meteor.publish('posts', function(){
return Posts.find()});
}
if(Meteor.isClient) {
Meteor.subscribe('posts');
}
`
任何想法或建議嗎?當我在Mongo shell中運行db.posts.insert({title:「postname})時,新的帖子在瀏覽器中立即異步顯示,所以我知道數據庫正在運行。 我很早就在教程中所以我覺得這不應該發生。
看起來像'Posts = new Mongo.Collection('posts');'只在客戶端定義。它可能位於'/ client/... js'文件中,還是位於'Meteor.isClient'塊中? – 2014-11-06 02:35:09
不,它是在'/ meteorapp/lib/collections'文件夾中定義的。它在Mongo shell中定義並工作得很好,但不適用於客戶端/瀏覽器端的終端。它位於posts.js文件中。 – zavtra 2014-11-06 02:38:35