RethinkDB:订阅数组中项的更改

RethinkDB: Subscribing to changes of items in an array

本文关键字:数组 RethinkDB      更新时间:2023-09-26

user.posts是一个对象数组。我试图只在用户更改帖子或添加新帖子时触发回调。我应该如何过滤这个查询,以确保我只在用户的帖子更改时获得更新?我如何知道帖子数组中的哪个帖子发生了变化?谢谢你的帮助。

r.table('users')('posts').changes().filter(function(posts){
  posts('new_value').difference(posts('old_value'))
 }).run(conn, (err, cursor) => {
  if (err) return
  cursor.each((post) => {
    // This is a single post that just changed, do something with it...
  })
})

由用户行组成的用户

user = {id: '', posts:[
  {id: '', content: ''},
  {id: '', content: ''},
], other: ''}

可以写r.table('users').changes().filter(function(change) { return change('new_val')('posts').setDifference(change('old_val')('posts')).ne([]); })