0

I'm trying to add an element in an array but can't figure out what is causing my problem, Don't know if i have to do an insert or an update anyway tried both, both not working

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 
}

i got the error

UserIds that can send messages on this test must be an array",
EyTa
  • 109
  • 3
  • 10

1 Answers1

1

You just need to change the $set by $push

  Tests.update(box_id, { "$push": { "current_test.senders": USER._id} })
Taieb
  • 920
  • 3
  • 16
  • 37