Hello, I have a problem with displaying data I have inserted, the insertion is done correctly but for some reason it isn’t displaying, I have installed meteortoys to see if the data was inserted correctly but it always shows 0 and I have subscribe to my collection.
Here’s my publication
//this code was giving by another member of this forum, thanks again
Meteor.publish('profiles', function () {
const { userId } = this;
if(userId){
return Profiles.find({ userId });
}
});
The subscription, nothing out of the ordinary
if (Meteor.isClient) {
Meteor.subscribe('profiles');
}
And my insertion along with the helpers, I’ve created a profile collection for security reasons, I honestly don’t see any errors but I may be overlooking something, so thanks in advance and any advice is highly appreciated.
Template.Profile.events({
"submit #profile-update": function (evt, err) {
evt.preventDefault();
var age = evt.target.age.value;
var phone = evt.target.phone.value;
var job = evt.target.job.value;
var bday = evt.target.bday.value;
var city = evt.target.city.value;
var hi = evt.target.hi.value;
var sn = evt.target.sn.value;
if (Meteor.user && Profiles == null) {
Profiles.insert({
_id: Meteor.user()._id,
Age: age,
Phone: phone,
Job: job,
BirthDate: bday,
City: city,
HealthInsurance: hi,
SecurityNumber: sn
});
Bert.alert('Edicion exitosa', 'success', 'growl-top-right');
} else
if (Profiles != null) {
Profiles.update({
Age: age,
Phone: phone,
Job: job,
BirthDate: bday,
City: city,
HealthInsurance: hi,
SecurityNumber: sn
});
} else {
Bert.alert(err.reason, "danger", "growl-top-right");
}
},
'change .PicInput': function (evt, template) {
FS.Utility.eachFile(evt, function (file) {
Images.insert(file, function (err, fileObj) {
if (err) {
throw new error(err.reason, "danger", "growl-top-right")
} else {
var userId = Meteor.user()._id;
var imageURL = {
"profile.image": "/cfs/files/images/" + fileObj._id
};
Meteor.users.update(userId, {
$set: imageURL
});
}
})
});
}
});
Template.Profile.helpers({
profiles: function () {
return Profiles.find({});
},
images: function () {
if (Meteor.user) {
return Images.find({});
}
}
});