중포 기지 Firestore 또는 쿼리

어떻게 데이터를 얻을 수여 여러 개 값을 하나의 필드? 예를 들어,내가 데이터베이스에 게시물과 함께하고 싶은 쿼리를 위해 모든 게시물을 어디 blogId 는 1 또는 2,정렬에 의한 타임스탬프입니다.

collection("posts").whereEqualTo("blogId", "1")
.whereEqualTo("blogId", 2).orderBy("timestamp", Query.Direction.DESCENDING).limit(50)

위의 코드 작동하지 않:(

이것을 달성하는 방법? 감사합니다:)

질문에 대한 의견 (1)

결합할 수 있습니다.관찰 가능하고 중 하나로 돌아

orQuery(){

    const $one = this.afs.collection("posts", ref => ref.where("blogId","==","1")).valueChanges();
    const $two = this.afs.collection("posts", ref => ref.where("blogId","==","2")).valueChanges();

    return combineLatest($one,$two).pipe(
        map(([one, two]) => [...one, ...two])
    )
}

getOr(){
    this.orQuery().subscribe(data => console.log(data))
}
해설 (0)

나't 찾을 문서화하는 기능을 함께 또는 조건. 할 수 있지만 말할께 귀하의 요구 사항에blogId다음과 같다:

WHERE blogId > 0 AND blogId < 3

이 코드:


collection("posts")
.where("blogId", ">", "0")
.where("blogId", "
해설 (11)

또는연산자가 허용되지 않습에서 중포 기지 firestore. 일반적으로 사용하여 중포 기지할 수 있는 구문에 부르 두 가지 컬렉션: const res1=async 컬렉션("글"ref=>ref.치(&#39;blogId&#39;, &#39;==&#39;, 1).get(); const res2=async 컬렉션("글"ref=>ref.치(&#39;blogId&#39;, &#39;==&#39;, 2).get(); 고 병합할 수 있습기 전에 결과를 제공하는 뷰입니다.

그러나 이 경우에 있는 blogIds 할 수 있는 구문을 사용: 컬렉션("글").orderBy(&#39;blogId&#39;).위치는(1).endAt(2);

e.d

해설 (0)

Firestore 지원""쿼리이 목적에 적합합니다.

쿼리는 다음과 같이 보일 것입니다.

database.collection("collectionName").where("fieldName", "in", ["fieldValue1", "fieldValue2"]);

할 수 있는 최대 10 값(fieldValueX)을 확인""습니다.


코드 OP 원하는 다음과 같습니다:

database.collection("posts").where("blogId", "in", ["1", "2"]); 
해설 (0)

Firestore 가 없음또는검색어입니다. 그들은 방법은 당신이'd 를 수행하는 실행하여 두 개의 쿼리와 접합니다.

당신은 예를 들어:

``js const 검색=(key,value)=>콜렉션('사용자는').치(열쇠, '==', 값).get().다음(doc=>doc.데이터())

약속입니다.모든([검색('이름','요'),검색('이름','Johnny')]) .다음(([하나,둘])=>하나입니다.concat(두)) .다음(allResults=>dothings()) ``

해설 (0)

collection("posts").start("blogId", "1")
.end("blogId", 2).orderBy("timestamp", Query.Direction.DESCENDING).limit(50)
해설 (0)

중포 기지가 듣고 우리의 요청과 그들이 포함되어 있에서쿼리에서는7 월,2019. It's 종류의또는쿼리할 수 있는 최10필터입니다.

드:

collection("posts").whereIn("blogId", Arrays.asList("1", "2"))
.orderBy("timestamp", Query.Direction.DESCENDING).limit(50);

중포 기지 설명서

해설 (0)