I have server & client files and am trying to send some data to Javascript rather than into a template. In the template, I can output some values, but I need it in JS to add markers to Leaflet.
I guess, there's no sense to funnel the data through templates to get it into JS and into Leaflet, right?
What am I doing wrong?
shell
$ mongo
MongoDB shell version: 2.4.9
connecting to: test
> use atms
switched to db atms
> db.markers.count()
1868
Running the server:
$ MONGO_URL=mongodb://127.0.0.1:27017/atms meteor
lib/collections.js
Markers = new Meteor.Collection('markers');
In the client/client.js, I try to get records from the collection, but it's empty:
Template.hello.helpers({
marks: function () {
// this data renders correctly on map
return Markers.findOne({})
}
});
Template.hello.onRendered(function() {
// this data is empty in console
var query = Markers.find().fetch();
console.log(query);
});
In the template, it shows one record, which means the connection works. But console output is []
.