0

I'm trying to update multiple arrays inside the table users.I think I'm supposed to use forEach for nested queries, but can't make it work. Below is what I tried:

r.db('mydb').table('users').forEach(
      function(user){
        return update({
          upvotelist: user('upvotelist').append(0),
          downvotelist: user('downvotelist').append(0)}
        )
      } 
    )
João Lima
  • 430
  • 1
  • 6
  • 11

1 Answers1

1

You can just do this with update by itself:

r.db('mydb').table('users').update(function(user) {
  return {
    upvotelist: user('upvotelist').append(0),
    downvotelist: user('downvotelist').append(0)};
})

foreach is for more complicate situations where you want to issue a write to a row based on another row.

mlucy
  • 5,249
  • 1
  • 17
  • 21