Hello, I’ve created a collection to store additional info of the user, the info is successfully inserted in the collection but when I want to display it, it doesn’t appear and I can’t seem to find the problem.
Here’s my Profiles collection
export const Profiles = new Mongo.Collection('profiles');
const ProfileSchema = new SimpleSchema({
Age: {
type: Number,
label: "Edad",
optional: true
},
Job: {
type: String,
label: "Trabajo",
optional: true
},
Phone: {
type: Number,
label: "Telefono",
optional: true
},
Address: {
type: String,
label: "Direccion",
optional: true
},
Gender: {
type: String,
label: "Genero",
optional: true
},
City: {
type: String,
label: "Ciudad",
optional: true
},
SecurityNumber: {
type: Number,
label: "Cedula",
optional: true
},
HealthInsurance: {
type: Number,
label: "Seguro medico",
optional: true
},
Rnc: {
type: String,
label: "Rnc",
optional: true
},
Exequatur: {
type: Number,
label: "Exequatur",
optional: true
},
BirthDate: {
type: Date,
label: "Fecha de nacimiento",
optional: true
},
});
Profiles.attachSchema(ProfileSchema);
Profiles.allow({
insert: function () {
return true;
},
update: function () {
return true;
},
remove: function () {
return true;
}
});
The event for inserting the data:
Template.Profile.events({
"submit #profile-update": function (evt) {
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.insert({
_id: Meteor.user()._id,
Age: age,
Phone: phone,
Job: job,
BirthDate: bday,
City: city,
HealthInsurance: hi,
SecurityNumber: sn
});
Bert.alert('Edicion exitosa', '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});
}
})
});
}
});
And the helper
Template.Profile.helpers({
UserInfo: function (info) {
if (Meteor.user) {
return Profiles.find({});
}
},
images: function() {
if(Meteor.user){
return Images.find({});
}
}
});
Also I don’t know if is this is important but I’m using oncreateuser to modify the user’s initial data while signing up
/**To modify the user's data */
Accounts.onCreateUser(function (options, user) {
if (!user.profile) {
user.profile = {};
}
user.profile.firstname = options.firstname;
user.profile.secondname = options.secondname;
user.profile.surname = options.surname;
user.profile.lastname = options.lastname;
user.profile.email = options.email;
AssignRole(options, user); //ignore this
return user;
});
I have subscribe to the profiles collection on the client side and published on the server side too:
Meteor.publish('profiles', function () {
return Meteor.users.find({}) && Profiles.find({});
})