2016-10-15 1 views
1

누락 된 필드 및 누락 된 값에 따라 필터링하려면이 SO 스레드 RethinkDB - Find documents with missing field의 누락 된 필드가있는 테이블에서 모든 문서를 찾을 수있는 답을 찾았습니다. 다른 분야.rethinkdb - hasFields 여러 개의 누락 된 조건이있는 모든 문서를 찾으려면

email 필드가 누락되어 있고 isCurrent: 값이 1 인 모든 문서를 반환하고 싶습니다. 따라서 전자 메일 필드가 누락 된 현재 클라이언트를 모두 반환하여 필드를 추가 할 수있게하려고합니다.
rethink 사이트의 문서는이 사례를 다루지 않습니다.

여기에 최선을 시도입니다 :

r.db('client').table('basic_info').filter(function (row) { 
    return row.hasFields({email: true }).not(), 
/*no idea how to add another criteria here (such as .filter({isCurrent:1})*/ 

    }).filter 

답변

1

실제로 배치에 이메일 주소를 공급, 하나 filter에서 그것을 할 수 있습니다.

r.db('client').table('basic_info').filter(function (row) { 
    return row.hasFields({email: true }).not() 
     .and(row.hasFields({isCurrent: true })) 
     .and(row("isCurrent").eq(1)); 
}) 

나 :

r.db('client').table('basic_info').filter(function (row) { 
    return row.hasFields({email: true }).not() 
     .and(row("isCurrent").default(0).eq(1)); 
}) 
그리고, 또한, 현재의 솔루션보다 빨라집니다
0

난 그냥 체인 여러 .filter 명령 할 수 깨달았다. 다음은 나를 위해 일한 내용은 다음과 같습니다

r.db('client').table('basic_info').filter(function (row) { 
    return row.hasFields({email: true }).not() 
}).filter({isCurrent: 1}).; 

나의 다음 퀘스트 : 배열로이 모든 것을 넣고

관련 문제