RethinkDB:订阅数组中项目的更改
RethinkDB: Subscribing to changes of items in an array
user.posts
是一个对象数组。我试图仅在用户更改 post 或添加新的时触发回调。我应该如何过滤此查询以确保我只在用户的 post 发生更改时获得更新?我怎么知道 post 数组中的哪个 post 发生了变化?谢谢你的帮助。
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([]); })
.
user.posts
是一个对象数组。我试图仅在用户更改 post 或添加新的时触发回调。我应该如何过滤此查询以确保我只在用户的 post 发生更改时获得更新?我怎么知道 post 数组中的哪个 post 发生了变化?谢谢你的帮助。
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([]); })
.