进出口新的流星,我有一个问题,我无法摆脱的MongoDB集合(我用的铁路由器)流星无法获得数据
/client/routes.js
Router.route('/page', function(){
this.render('page');
});
/客户机/ foo.js
city = new Mongo.Collection('data');
if (Meteor.isClient) {
Template.foo.helpers({
data: function(){
return city.find();
}
});
}
客户端/视图/ foo.html
<template name="foo">
{{#each data}}
{{> all_data}}
{{/each}}
</template>
<template name="all_data">
<li>{{city}}</li>
</template>
铬控制台命令city.find()给我:
1 ... n.Cursor {集合:LocalCollection,分拣机:空,_selectorId: 未定义,匹配:M ... o.Matcher,跳过:未定义...}
和蒙戈控制台db.data.find()它做工精细
我认为有一个问题连接到MongoDB的
尝试'console.table(city.find()。取()) ;'在你的客户端代码或控制台中。 find()方法返回一个游标,findOne()或find()。fetch()返回一个文档数组。 – Billybobbonnet
'city.find()。fetch()'只返回'[]'和'findOne()'返回undefined – Gintoki
如果你删除了autopublish包,记住你需要定义'allow-deny'规则,出版物,以便在客户端访问您的数据。请参阅https://www.discovermeteor.com/blog/understanding-meteor-publications-and-subscriptions/。您还需要在'both'文件夹中定义您的集合,因此它指向服务器和客户端上的相同集合(如果名称匹配,则不确定这是否必需)。 – Billybobbonnet