RethinkDB:无法在急切的流上调用“更改”
RethinkDB: Cannot call `changes` on an eager stream
我有 table 个用户,每个用户都有一群朋友。
其中的一个文档看起来像这样:
{
id: "0ab43d81-b883-424a-be56-32f9ff98f7d2",
username: "testUser1234",
friends: [
"04423c56-1890-4028-b38a-cb9aff7112de" ,
"05e4e613-2131-408c-b0ae-a952f3007405" ,
"0395ee53-8ab0-48cc-aa4e-41aad93b8737"
]
}
我想关注用户好友的变化。像这样的查询会给我一个朋友列表:
r.db("Test").table("Users").get("0ab43d81-b883-424a-be56-32f9ff98f7d2")("friends").map(function(id) {
return r.db("Test").table("Users").get(id);
})
但是,当我尝试在最后抛出一个 .changes()
时,RethinkDB 告诉我它不起作用:
RqlRuntimeError: Cannot call `changes` on an eager stream in:
r.db("Test").table("Users").get("0ab43d81-b883-424a-be56-32f9ff98f7d2")("friends").map(function(var_19) { return r.db("Test").table("Users").get(var_19); }).changes()
有没有办法让这个工作?恐怕我唯一的选择是订阅朋友列表(在我的应用程序中)并在更改时更新对实际朋友的订阅:
r.db("Test").table("Users").getAll(friendId1, friendId2 , friendId3, friendId4).changes()
不是世界末日,但我真的很兴奋能够完全在数据库中完成它。
此外,谁能解释一下 "eager stream" 是什么?我认为这与惰性评估与立即评估有关,但我不知道如何判断决定流是否急切的标准。
您可以在某些转换之前附加 .changes
。
r.db("Test")
.table("Users")
.get("0ab43d81-b883-424a-be56-32f9ff98f7d2")
.changes()
.getField('new_val')('friends')
.map(function(id) {
return r.db("Test").table("Users").get( id );
})
基本上每次有变化,都会执行map
函数。目前,这是使用 .changes
执行此类操作的唯一方法,但在即将推出的 RethinkDB 版本中会发生变化。
受this post启发:
,我可以使用以下格式进行查询
r.db("Test").table('Users').getAll(r.args(
r.db('Test').table('Users').get("0ab43d81-b883-424a-be56-32f9ff98f7d2")('friends')
)).changes()
我有 table 个用户,每个用户都有一群朋友。
其中的一个文档看起来像这样:
{
id: "0ab43d81-b883-424a-be56-32f9ff98f7d2",
username: "testUser1234",
friends: [
"04423c56-1890-4028-b38a-cb9aff7112de" ,
"05e4e613-2131-408c-b0ae-a952f3007405" ,
"0395ee53-8ab0-48cc-aa4e-41aad93b8737"
]
}
我想关注用户好友的变化。像这样的查询会给我一个朋友列表:
r.db("Test").table("Users").get("0ab43d81-b883-424a-be56-32f9ff98f7d2")("friends").map(function(id) {
return r.db("Test").table("Users").get(id);
})
但是,当我尝试在最后抛出一个 .changes()
时,RethinkDB 告诉我它不起作用:
RqlRuntimeError: Cannot call `changes` on an eager stream in:
r.db("Test").table("Users").get("0ab43d81-b883-424a-be56-32f9ff98f7d2")("friends").map(function(var_19) { return r.db("Test").table("Users").get(var_19); }).changes()
有没有办法让这个工作?恐怕我唯一的选择是订阅朋友列表(在我的应用程序中)并在更改时更新对实际朋友的订阅:
r.db("Test").table("Users").getAll(friendId1, friendId2 , friendId3, friendId4).changes()
不是世界末日,但我真的很兴奋能够完全在数据库中完成它。
此外,谁能解释一下 "eager stream" 是什么?我认为这与惰性评估与立即评估有关,但我不知道如何判断决定流是否急切的标准。
您可以在某些转换之前附加 .changes
。
r.db("Test")
.table("Users")
.get("0ab43d81-b883-424a-be56-32f9ff98f7d2")
.changes()
.getField('new_val')('friends')
.map(function(id) {
return r.db("Test").table("Users").get( id );
})
基本上每次有变化,都会执行map
函数。目前,这是使用 .changes
执行此类操作的唯一方法,但在即将推出的 RethinkDB 版本中会发生变化。
受this post启发:
,我可以使用以下格式进行查询r.db("Test").table('Users').getAll(r.args(
r.db('Test').table('Users').get("0ab43d81-b883-424a-be56-32f9ff98f7d2")('friends')
)).changes()