ユーザー コレクションにフィールドを追加するにはどうすればよいですか。オプション オブジェクトには、ユーザー名、メール パスワード、プロフィールの 4 つのフィールドが許可されていることを理解しています。Accounts.onCreateUser で、ルート レベル (プロファイル フィールド内ではなく) にフィールドを追加する方法はありますか?
現在のところ、解決策は、Accounts.createUser を使用してプロファイルにフィールドを追加し、このフィールドをルート レベルにコピーしてから、Accounts.onCreateUser を使用してプロファイルのフィールドを削除することです。これは、以下の例の「userType」に対して行われます
クライアント.js
Template.joinForm.events({
'submit .form-join': function(e, t) {
e.preventDefault();
var firstName = t.find('#firstName').value,
lastName = t.find('#lastName').value,
email = t.find('#email').value,
password = t.find('#password').value,
username = firstName + '.' + lastName,
profile = {
name: firstName + ' ' + lastName,
userType: selectedUserType // this is copied to root level and deleted from profile.
};
Accounts.createUser({
//NEWFIELD1: [],
//NEWFILED2: [],
email: email,
username: username,
password: password,
profile: profile
}, function(error) {
if (error) {
alert(error);
} else {
Router.go('/');
}
});
}
});
サーバー.js
Accounts.onCreateUser(function(options, user) {
if (options.profile) {
if (options.profile.userType) {
user.userType = options.profile.userType;
delete options.profile.userType;
}
user.profile = options.profile;
}
return user;
});