Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rethinkdb 如何在数据库中执行复杂的批量更新_Rethinkdb - Fatal编程技术网

Rethinkdb 如何在数据库中执行复杂的批量更新

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);

我试图定期计算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);
  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);