1

I am hitting the following problem: Suppose that I have the following structure:

{
    "id": 1,
    "data": {
       "arr": [{"text":"item1"}]
    }
}

And the following query:

r.db('test').table('test').get(1).update(function (item) {
    return {
        data: {
          arr: item('data')('arr').map(function (row) {
             return r.branch(
                  row('text').eq('item1'),
                  row.merge({updated:true}),
                  row
             )
          })
        }
    }
})

I am listening for changes in this specific array only, and when the item is updated both create and delete events are emitted. I really need to receive an update event, e.g. old_val is not null and new_val is not null.

Thanks in advance guys

Community
  • 1
  • 1
Georgi-it
  • 3,676
  • 1
  • 20
  • 23

2 Answers2

2

After all, I decided to drop the embedded array and use table joins, this avoids all possible hacks.

Georgi-it
  • 3,676
  • 1
  • 20
  • 23
1

You can use something like this

r.db('test').table('test')('data')('arr').changes()
  .filter(function(doc) {
    return doc('new_val').ne(null).and(doc('old_val').ne(null))
  })

I'll only show update to array. If you need to get access to other document field, try this:

r.db('test').table('test').changes()
  .filter(function(doc) {
    return doc('new_val')('data')('arr').ne(null).and(doc('old_val')('data')('arr').ne(null))
  })
kureikain
  • 2,304
  • 2
  • 14
  • 9