3

I've checked other related questions, in particular this one. But since that was answered it seems like rethink's handling of nested fields has changed.

I'm trying to modify the nested arrays 'amy' and 'joe':

{
    "id":  "blah" ,
    "schedules": {
        "amy": ['some', 'stuff', 'here'],
        "joe": ['more', 'stuff', 'here']
    }
}

I've tried all kinds of different approaches, but I can't get it to work in a single call to the database. Instead, I'm having to grab the existing array using one call:

r.table('whatevs').get('blah').pluck({schedules: {amy: true}})

this gives me something that looks like:

"schedules": {
    "amy": ['some', 'stuff', 'here']
}

so I pull out schedules.amy and modify the array then...

r.table('whatevs').get('blah').update({schedules: {amy: [modified_array]}})...

What I'd like to do is modify the arrays in place with a single query using .difference() and .append(). It seems like this is now possible, but no matter what syntax I try it gets rejected.

1 Answer 1

4

If you want to update a single key that's an array, you can do so like this:

r.table('whateves').get('blah').update(function(row) {
  return {schedules: {amy: row('schedules')('amy').append('new_value')}};
});
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.