我想从 0 到多个项目的集合中随机选择一个项目,如果它存在,请更新特定字段。如果该项目不存在,我希望该函数不执行更新并返回 null。
我当前的 REQL 代码:
r.db('test').table('test')
.filter({
something: true
}).sample(1).nth(0).default(null).update(function(thing) {
return r.branch(
thing.ne(null),
thing.without('reserve'),
null
)
}, {
returnChanges: true
});
这总是返回错误:Expected type SELECTION but found DATUM
我不确定如何用 REQL 解决这个问题。