Im new to meteor, I have a problem I can't get collection from mongodb (i use iron router )
/client/routes.js
Router.route('/page', function(){
this.render('page');
});
/client/foo.js
city = new Mongo.Collection('data');
if (Meteor.isClient) {
Template.foo.helpers({
data: function(){
return city.find();
}
});
}
client/views/foo.html
<template name="foo">
{{#each data}}
{{> all_data}}
{{/each}}
</template>
<template name="all_data">
<li>{{city}}</li>
</template>
in chrome console the command city.find() give me:
L…n.Cursor {collection: LocalCollection, sorter: null, _selectorId: undefined, matcher: M…o.Matcher, skip: undefined…}
and in mongo console db.data.find() it work fine
i think there a problem to connect to mongodb
console.table (city.find().fetch());in your client code or console. Thefind()method returns a cursor, thefindOne()or find().fetch() returns an array of documents.city.find().fetch()return just[], andfindOne()return undefinedallow-denyrules and publications in order to access your data on the client side. See discovermeteor.com/blog/…. You also need to define your collection in abothfolder, so it refers to the same collection both on server and client (not sure this is mandatory if names matches).