I have two collection here users(which is Meteor Accounts system) and userProfile(subducument for Meteor users)
I want my userProfile will be reference for Meteor users collection, I have my following code …
Meteor.methods({
'users.insert'(userData, userProfile) {
// Validation for Users Data Entry
check(userData, {
email: String,
password: String,
profile: {
firstName: String,
lastName: String,
userType: String,
address: String,
}
});
check(userProfile,{
firstName: String,
lastName: String,
userType: String,
address: String,
});
try{
var getProfile = UserProfiles.insert({
firstName: userProfile.firstName,
lastName: userProfile.lastName,
userType: userProfile.userType,
address: userProfile.address,
createdAt: new Date(),
});
Accounts.createUser({
email: userData.email,
password: userData.password,
profile: getProfile,
});
} catch(error) {
throw new Meteor.Error('error', error.error);
}
},
});
I would like to insert (on the server) a user profile document with the current user, as a reference (not as an embedded document).
example:
what I am expecting for my users is
{
"_id" : "jzyNQJqXuHneNgqCY",
"createdAt" : ISODate("2018-12-13T02:11:39.623Z"),
"services" : {
"password" : {
"bcrypt" : "$2b$10$DXCxgtcvuCNxq835OC0Z7uc1s7N0e4vnE6fx9tLoi1T7Ll9V7Eyoi"
}
},
"emails" : [
{
"address" : "cc@gmail.com",
"verified" : false
}
],
"profile" : {
"id": "uPneJEb3abETkizHE",
"firstName" : "cc",
"lastName" : "cc",
"userType" : "admin",
"address" : "cc"
}
}
I searched many times in google but there is no good answer for me … Anyone can help me here ?