Firebase Firestore - Alternative OR Request

In this Firebase Firestore - OR query, they said there was no OR query. This means that I cannot easily request elements that have an identifier that is in the array that I received earlier.

// What I want
documentRef
    .whereField("itemId", isEqualTo: "id1")
    .orWhereField("itemId", isEqualTo: "id3")

// or
documentRef
    .whereField("itemId", in: idArray)

Since this does not work, which option is better to request from my data?


  • Get all data and check locally

I could get all my records and just check the identifiers on the device, but the problem is that it can be up to 1000 records, and the user may need only three of them.


  1. Separate queries for all items

whereField("itemId", isEqualTo: "id") , . , , , , , . ( )


, Item: Items/itemid/PurchasedBy/uid, , , , . , .


:

Users/uid/PurchasedItems/itemid

    payedInMoney: "$0.00"
    payedInCoins: "100"
    itemId: "itemid"
    timeStamp: timestamp

Items/itemid

    itemId: "itemid"
    // Other item info

Edit:

, RTDB, addSnapshotListener Firestore RTDB. , , Firestore 4 , RTDB ( ).

// iPad 5 (2017) - iOS 11
RTDB:  50-100ms
FST:  350-450ms

// iPad Air (2014) - iOS 10
RTDB: 100-150ms
FST:  700-850ms

// iPad Mini (2012) - iOS 9
RTDB: 150-200ms
FST:  2900-3200ms

2:

RTDB, Firestore .

3:

, , - .

, Firestore, , RTDB, .

+4
1

. , , "", PurchasedItems, .

, PurchasedItems:

Users/uid/PurchasedItems/itemid

    // Existing 
    payedInMoney: "$0.00"
    payedInCoins: "100"
    itemId: "itemid"
    timeStamp: timestamp

    // Add these
    name: "Item Name"
    url: "http://foo.bar/123"

, , , .

+1

Source: https://habr.com/ru/post/1687706/


All Articles