2017-12-30 47 views
0

예를 들어 특정 색, 작성자 및 범주를 설정할 수있는 내 책 목록 용 동적 필터가 있습니다. 이 필터는 한 번에 여러 색상을 여러 범주로 설정할 수 있습니다.Firestore : 여러 조건부 where 절

Book > Red, Blue > Adventure, Detective. 

어떻게 "조건"을 조건부로 추가 할 수 있습니까? 당신은 API 문서에서 볼 수 있듯이

firebase 
    .firestore() 
    .collection("book") 
    .where("category", "==",) 
    .where("color", "==",) 
    .where("author", "==",) 

    .orderBy("date") 
    .get() 
    .then(querySnapshot => {... 

답변

3

collection() 방법은 CollectionReference 반환합니다. CollectionReference는 Query까지 확장됩니다. Query.where()Query.orderBy()도 Query 개체를 반환합니다. 따라서 다음과 같이 코드를 다시 작성할 수 있습니다.

이제 각 조건에 적용 할 필터를 알아낼 수 있습니다.

+0

이것은 나에게 매우 유용합니다! 고맙습니다! –