return undefined Posts.findOne();

时间:2015-09-14 15:10:50

标签: javascript mongodb meteor collections

我在Meteor中很新,所以我正在关注Discove Meteor Book。但我发现了一些麻烦。当它说:在两个新窗口中打开浏览器控制台(第4章 - 集合):

  • 首先,它不能让我同时打开2个窗口。它只部署一个控制台窗口(它似乎属于整个浏览器系统。)
  • 其次,好吧我只使用一个浏览器控制台窗口。但是,当我尝试运行Posts.findOne();它应该部署 {title:"一个新帖子",_ id:LocalCollection._ObjectID};但它部署" undefined"。实际上我没有得到它,因为我有这个:Posts = new Mongo.Collection('posts'); lib文件夹下的(filename:posts.js)(应该在双方都有效(客户端和服务器)。

关于为什么是未定义的任何想法?

1 个答案:

答案 0 :(得分:-1)

Just like insecure, all new Meteor apps are created with the autopublish package.
If you meteor remove autopublish you need to publish your collections content and subscribe to it. If you haven't done so, you won't see any records since the client does not pull data from the server, this adds security measures to Meteor.

To solve: meteor add autopublish then check the browser console for published records.