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
The collections need to be defined on both server and client side for autopublish to work -- files in /client are only executed on the client side, so
city = new Mongo.Collection('data');
is unknown to the server.Move the file
into the parent directory
And it will likely work