2017-08-09 10 views
0

rethinkdbでブランチ更新ロジックを使用する。別の値と一致する値に基づいて値を更新し、適切な値を設定する必要があります。値が同じ場合は、既存の値を使用する必要があります。Rethinkdbブランチが偽に評価された場合は既存の値を使用

r.db('testdb').table('great_table').get(1).update(source => { 
    return r.branch(source('some_other_id').eq(1), {read: false}, /* use existing value */); 
}) 

は、次のことをしようとしました:

r.db('testdb').table('great_table').get(1).update(source => { 
    return r.branch(source('some_other_id').eq(1), {read: false}, source('checked')); 
}) 

私はこれがあるしようとしたとき、私は受け取ったエラー:クエリで

{ 
    "deleted": 0 , 
    "errors": 1 , 
    "first_error": "Inserted value must be an OBJECT (got BOOL): false" , 
    "inserted": 0 , 
    "replaced": 0 , 
    "skipped": 0 , 
    "unchanged": 0 
} 

答えて

1

オブジェクトを期待再考boolに合格しようとしているが。

だから、あなたのクエリは(あなたがsource('checked')値を保存したいフィールドに依存して)次のようになります。

r.db('testdb').table('great_table').get(1).update(source => { 
    return r.branch(source('some_other_id').eq(1), {read: false}, {read: source('checked')}); 
}) 
関連する問題