2016-01-20 130 views
1

我试图用mongodb连接我的应用程序。添加静态数组数据的帖子效果很好。流星连接

问题:现在没有任何内容显示在{{post}}之下。如果我检查我的数据库,则已插入数据。

数据库中插入+代码:

db.calposts.insert({ post: "Hello world!", createdAt: new Date() }); 
WriteResult({ "nInserted" : 1 }) 

{{#each calposts}} 
    {{> posts}} 
{{/each}} 

<template name="posts"> 
<div class="panel-post" id="post-draggable"> 
    <span>{{post}}</span> 
</div> 
</template> 

if (Meteor.isClient) { 
    Template.calendar.helpers({ 
    calposts: function() { 
    return CalPosts.find({}); 
    } 
    }); 
} 
+0

你发现'CalPosts'但你插入'db.calposts'?应该是'CalPosts.insert()' –

+0

db.calposts.insert ..是用于添加数据的mongo shell命令。它指的是CalPosts = new Meteor.Collection('calposts'); – Flo

回答

0

你发布calpost收集到客户端? 如果没有,请在需要使用Meteor.publish()的服务器文件夹中,然后在客户端运行Meteor.subscribe()以订阅该出版物。

查看此页面上meteor.com关于发布和订阅的详细信息:

https://www.meteor.com/tutorials/blaze/publish-and-subscribe

+0

谢谢。是的,我加了 Meteor.subscribe(“calposts”); (){ } });}} 和服务器 eteor.publish(“calposts”,function(){ return CalPosts.find(); }); 但仍然没有结果.. – Flo

+0

你是否收到任何流星错误以及没有显示的数据? – chackerian