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",
0

1 Answer 1

1

You just need to change the $set by $push

  Tests.update(box_id, { "$push": { "current_test.senders": USER._id} })
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.