在群聊中添加参与者
问题描述:
我想在群聊中添加的参与者,但我没有得到任何错误,但没有什么是这里发生的一切是我的代码:在群聊中添加参与者
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)
})
}
})
答
该id是流星收藏更新的第一个参数。
见:https://docs.meteor.com/api/collections.html#Mongo-Collection-update
尝试
Meteor.methods({
addMember: function(groupId,email){
Groups.update(groupId,
{$addToSet: {participants:{"emails":email}}}
);
}
});
+0
他们已经有这个 - {_id:}的groupId - 3号线 – rubie
答
你应该使用圆点符号里面participants
更新emails
领域。
https://docs.mongodb.com/v3.2/core/document/#document-dot-notation
只是
{$addToSet: {"participants.emails":email}}
取代
{$addToSet: {participants:{"emails":email}}}
你可以用组数据库架构更新,请 – rubie