Reputation: 253
For some reason i can't get data displayed from my Locations collection. No matter what i type i get [object Object] when i write {{myPlaces}} in the HTML. Should i not get a list of the entire content and all fields listed? Can someone explain this, as I get all data from both Meteor.Users and Images. Thank you!
zipCodes.js:
import { Mongo } from 'meteor/mongo';
export const Locations = new Mongo.Collection('locations');
if (Meteor.isServer) {
Meteor.publish("locations", function () {
return Locations.find().cursor;
});
}
if (Meteor.isServer) {
Locations.batchInsert(
[
{
"country": "NO",
"zipcode": 1751,
"place": "Halden",
"county": "Ostfold",
"countyNumber": 1,
"municipality": "Halden",
"municipalityNumber": 101,
"lat": 59.1248,
"long": 11.3875,
"num": 4
},
{
"country": "NO",
"zipcode": 1752,
"place": "Halden",
"county": "Ostfold",
"countyNumber": 1,
"municipality": "Halden",
"municipalityNumber": 101,
"lat": 59.1248,
"long": 11.3875,
"num": 4
},
testPage.js
import './testPage.html';
import { Template } from 'meteor/templating';
import Images from '/lib/config/imagesCollection.js';
import { Locations } from '/imports/api/profiles/zipCodes.js';
Template.testPage.helpers({
// PROFILE INFORMATION
user: function() {
return Meteor.users.find();
},
// this = {{#each user}} context
userEmail: function() {
return this.emails[0].address;
},
userFirstName: function() {
return this.profile.first_name;
},
userTitle: function() {
return this.profile.work_title;
},
userMobile: function() {
return this.profile.mobile;
},
userZip: function() {
return this.profile.zipcode;
},
// PATH TO PROFILE PICTURE
imageLink: function() {
return Images.findOne({userId: this._id})['_id'];
},
// GEODATA TEST
myPlaces: function() {
return Locations.find({});
},
});
Upvotes: 0
Views: 51
Reputation: 20227
Your myPlaces
helper returns a cursor - i.e. a function that lets you refer to a list of Locations
. You need to iterate over that cursor to display individual documents using {{#each }}
. In your html do:
<template name="locations">
{{#each myPlaces}}
place: {{place}}
country: {{country}}
zipcode: {{zipcode}}
{{/each}}
</template>
Upvotes: 1