2016-09-03 2 views
1

RethinkDB에서 개체를 삭제하고 싶습니다. 조건이 충족되는 경우에만 삭제할 수 있습니다.RethinkDB에서 조건부 삭제

replace 및 null을 사용하는 다음 함수가 생겼습니다 (NULL이 replace()으로 전달되면 RethinkDB는 개체를 삭제합니다). 그러나 RethinkDB 반환을 유지하기 때문에이 작업을 얻을 수 없습니다. Cannot perform bracket on a non-object non-sequence null . 하나의 개체 만 바꾸려고합니다. 뭐가 잘못 되었 니?

r.db('test') 
    .table('test') 
    .get('123') 
    .replace(function(thing) { 
    return r.branch(thing('color').ne('green'), 
     r.error('Object color must be green to be deleted'), 
     null) 
    }, { returnChanges: true }) 

답변

2

행 123이 있습니까? 이 오류를 방지에 관심이 있다면 어쨌든,,, 그 일을하는 방법의 부부가 키 color에 대한 기본값을 제공 예를 들어 :

r.db('test') 
     .table('test') 
     .get("123") 
     .replace(function(thing) { 
     return r.branch(thing('color').default({color: null}).ne('green'), 
      r.error('Object color must be green to be deleted'), 
      null) 
     }, { returnChanges: true }) 
0

나는 Kludge는 지적으로 문제가 생각 get("123")에서 null을 가져옵니다. 지점에서이 조건을 테스트하려면 thing.eq(null)

관련 문제