1

Given an array and data structure as below, I want to remove any values that match from the removeVals from the table field tags. I've found a solution for changing, and tried with the deleteAt, but got an indexesOf is not a function error.

var removeTags = ["val1", "val3"];

{
  name: "test1",
  tags: ["val1", "val2", "val3", "val4", "val5"]
}

so I should be left with:

{
  name: "test1",
  tags: ["val2", "val4", "val5"]
}

My code so far:

var removeTags = ["val1", "val2"]
r.db('test').table('data').get('test1').update(function(row) {
  return row('tags').indexesOf(function(rl) {
    return r.expr(removeTags).contains(rl)
  })(0).do(function(idx) {
    return {
      roles: row('tags').deleteAt(idx)
    }
  })
});

This is the question/answer I was using as a reference. Any help would be appreciated, many thanks!

1 Answer 1

7

Nevermind, I've found the answer and it was far easier than I thought, I was over complicating things too much!

var removeTags = ['val1', 'val2'];
r.db('test').table('data').get('test1')
  .update({tags: r.row('tags').difference(removeTags)});

Anyway, hope this helps others

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.