2017-02-20 67 views
0

我目前擁有「計劃」集合,它是在創建表單提交時創建的。它插入如下:Meteor Mongo將數據添加到現有集合

Plans.insert({ 
    location, 
    address, 
    date, 
    time, 
    notes, 
    createdAt: new Date(), // current time 
    owner: Meteor.userId(), 
    username: Meteor.user().username, 
    attendees: [ 
    { 
     attender: [{ 
      user: String, 
      attending: Boolean, 
     }], 
    }, 
    ], 
}); 

然後,在複選框的點擊,我希望有一個新的attender對象添加到attendees陣列。到目前爲止,我已經嘗試過:

'click .notattending'() { 
    Plans.insert(
    {_id: this._id, 
     attendees: [{ 
      attender: [ 
       { 
       user: Meteor.user().username, 
       attending: false, 
       } 
      ], 
     } 
     ] 
    }, 
); 
}, 

但是它並沒有添加到Mongo集合中。這是做這件事的正確方法嗎?

+1

您應該更新文檔而不是插入 – collision

回答

1

您可以根據您的模式嘗試此操作。

Plans.update({ _id: this._id }, { 
    $push: { 
     attendees: { user: "", attending: true }, 
    }, 
});