First I’m sorry if this make no sense as I am a very new to Meteor.
Well, In a collections folder, I have a Profile.js to handle profile for the collection. I am not sure i am doing this right or wrong, but I want to create a new collection call Profile, which for storing a user profile data outside of user collection. I checked on Mongo, but there is no profile collection have been created. Is there something wrong? That’s the first question.
Second: I want to either insert or update user profile as the sign up form was only required email and password, so user have nothing on their profile. To let user update their own profile on a new profile collection, so I am using condition to see if the user has already inserted or it will insert new fields to its collection, below is also the code i am using to check, please help me to correct them.
Thanks
Profile = new Mongo.Collection('profile');
Profile.allow({
insert: function(userId, doc){
return !!userId;
},
update: function(userId, doc){
return !!userId;
}
});
Profilechema = new SimpleSchema({
profileId: {
type: String,
label: "Profile ID",
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
firstname: {
type: String,
label: "First Name"
},
lastname: {
type: String,
label: "Last Name"
},
title: {
type: String,
label: "Title"
},
aboutyou: {
type: String,
label: "About you"
},
createdAt: {
type: Date,
label: "Created At",
autoValue: function() {
return new Date()
},
autoform: {
type: "hidden"
}
}
});
Profile.attachSchema( Profilechema );
Meteor.methods({
if (Profile.find({}).count() === 0) {
insert_profile: function(firstname, lastname, title, aboutyou) {
check(firstname, String);
check(lastname, String);
check(title, String);
check(aboutyou, String);
}
Meteor.profile.insert(Meteor.userId(), {
firstname: firstname,
lastname: lastname,
title: title,
aboutyou: aboutyou
});
} else {
update_profile: function(firstname, lastname, title, aboutyou) {
check(firstname, String);
check(lastname, String);
check(title, String);
check(aboutyou, String);
// ... further validation
Meteor.profile.update(Meteor.userId(), {
firstname: firstname,
lastname: lastname,
title: title,
aboutyou: aboutyou
});
}
}
});