在小组聊天中添加参与者



我试图在小组聊天中添加参与者,但我没有遇到任何错误,但这里没有发生任何错误:

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}}}
     );
   }
});

您应该使用点符号来更新emails中的CC_1字段。

https://docs.mongodb.com/v3.2/core/document/#document-dot-notation

只需

替换{$addToSet: {participants:{"emails":email}}}

{$addToSet: {"participants.emails":email}}

最新更新