流星集合插入正在插入子文档而不是普通文档。参见下面的插入语句:
return Profile.insert({
_id: this.userId,
"firstName": firstname,
"lastName": lastname,
"state": state,
"mobile": mobile,
"alias": alias,
"email": email,
"bvn": bvn,
"createdAt": new Date(),
"updatedAt": new Date(),
});
这是MongoDB控制台中的结果:
meteor:PRIMARY> db.profile.find().pretty()
{
"_id" : "uNECMJJkCtQXhSs33",
**"firstName" : {
"firstName" : "firstName",
"lastName" : "lastName",
"state" : "state",
"mobile" : 55325235522535,
"alias" : "alias",
"email" : "email",
"bvn" : 6364634664
},**
"createdAt" : ISODate("2018-12-15T03:23:33.243Z"),
"updatedAt" : ISODate("2018-12-15T03:23:33.243Z")
}
以下是我的期望
meteor:PRIMARY> db.profile.find().pretty()
{
"_id" : "uNECMJJkCtQXhSs33",
"firstName" : "firstName",
"lastName" : "lastName",
"state" : "state",
"mobile" : 55325235522535,
"alias" : "alias",
"email" : "email",
"bvn" : 6364634664
"createdAt" : ISODate("2018-12-15T03:23:33.243Z"),
"updatedAt" : ISODate("2018-12-15T03:23:33.243Z")
}
答案 0 :(得分:0)
我已经解决了问题。我必须将所有参数作为对象从模板传递到方法中,如下所示:
模板
const updateProfile = {
"alias":target.aliasName.value,
"email":target.email.value,
"state":target.state.value,
"mobile":target.phone.value
}
Meteor.call('profileUpdate', updateProfile);
方法:
Meteor.methods({
'profileInsert'(profile) {
if (!this.userId) {
throw new Meteor.Error('not-authorized');
}
Match.test(profile.firstname, String);
Match.test(profile.lastname, String);
Match.test(profile.state, String);
Match.test(profile.mobile, Number);
Match.test(profile.bvn, Number);
Match.test(profile.email, String);
Match.test(profile.alias, String);
return Profile.insert(profile);
} });