Rethinkdb 如何在数据库中执行复杂的批量更新
我试图定期计算post表中所有项目的复杂Rethinkdb 如何在数据库中执行复杂的批量更新,rethinkdb,Rethinkdb,我试图定期计算post表中所有项目的复杂top分数 const {log10, max, abs, round} = Math; const topScore = post => { // from Reddit const {score, createdAt} = post; const order = log10(max(abs(score), 1)); const sign = score > 0 ? 1 : (score < 0 ? -1 : 0);
top
分数
const {log10, max, abs, round} = Math;
const topScore = post => { // from Reddit
const {score, createdAt} = post;
const order = log10(max(abs(score), 1));
const sign = score > 0 ? 1 : (score < 0 ? -1 : 0);
const seconds = Date.now() - createdAt;
return sign * order + seconds / 45000;
};
如何使用RejectDB javascript驱动程序实现这一点?您可以编写
r.table('post').update(r.js('(函数(post){…}),{nonAtomic:true})
其中是任意js代码。否则,您要么将代码转换为ReQL,要么将文档下载到客户机,更新它们,然后将它们写回服务器
// Update topScore every 60 seconds.
setInterval(() =>
r.table('post').update(post => post.topScore = topScore(post)).run();
, 60000);