我正在尝试在群组聊天中添加参与者,但我没有收到任何错误,但这里没有发生任何事情是我的代码:
Meteor.methods({
addMember: function(groupId,email){
Groups.update({_id:groupId},
{$addToSet: {participants:{"emails":email}}}
);
}
});
我的活动:
Template.editGroup.events({
'click .add': function() {
var id = this._id;
swal({
title: "An input!",
text: "Add an email address:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "Add email address"
},
function(email) {
if (email === false) return false;
if (email === "") {
swal.showInputError("You need to add email address!");
return false
}
Meteor.call("addMember",id,email)
})
}
})
答案 0 :(得分:0)
id是流星集合更新的第一个参数。
见:https://docs.meteor.com/api/collections.html#Mongo-Collection-update
试试吧
Meteor.methods({
addMember: function(groupId,email){
Groups.update(groupId,
{$addToSet: {participants:{"emails":email}}}
);
}
});
答案 1 :(得分:0)
您应该使用点表示法更新emails
内的participants
字段。
https://docs.mongodb.com/v3.2/core/document/#document-dot-notation
只需将{$addToSet: {participants:{"emails":email}}}
替换为
{$addToSet: {"participants.emails":email}}