【问题标题】:How to update array with Meteor [duplicate]如何使用 Meteor 更新数组 [重复]
【发布时间】:2018-11-09 10:21:09
【问题描述】:

我正在尝试在数组中添加一个元素,但不知道是什么导致了我的问题, 不知道我是否必须进行插入或更新,无论如何都尝试了,都不起作用

addUserToArray:function(userId,_id,email){
  check(_id, String)
  check(userId,String)
  check(email, String)
  var current_test = Modules.test.checkTestExist(test_id);
  const USER = Accounts.findUserByEmail(email)
  let test=USER._id
  if(userId==current_test.senders[0]){
    Tests.update(_id, {$set: {'name': name}}) // this one getting updated
    Tests.update(test_id, { $set: { "current_test.senders": test} }) // this is not working 
}

我收到了错误

UserIds that can send messages on this test must be an array",

【问题讨论】:

    标签: mongodb meteor


    【解决方案1】:

    你只需要通过 $push 改变 $set

      Tests.update(box_id, { "$push": { "current_test.senders": USER._id} })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      • 2017-06-30
      • 2019-02-01
      • 2021-08-18
      • 2015-09-01
      相关资源
      最近更新 更多