GitLiveApp / firebase-kotlin-sdk

A Kotlin-first SDK for Firebase
https://gitliveapp.github.io/firebase-kotlin-sdk/
Apache License 2.0
1.14k stars 155 forks source link

Add collection.select(fields) to Firestore #644

Closed mixtly87 closed 3 weeks ago

mixtly87 commented 3 weeks ago
Library Class Member Platforms
Firestore collection select all

Would be useful to support retrieving only specific fields from Firestore documents.

Something like:

fun getCities() = flow {
    firestore.collection("cities")
        .select("name", "population")
        .snapshots.collect { snapshot ->
        val cities = snapshot.documents.map { doc ->
            doc.data<City>()
        }.sortedBy { it.name }
        emit(cities)
    }
}

Idea is to only fetch needed fields and prevent network-transport of potentially heavy documents.

nbransby commented 3 weeks ago

Is this possible with the android SDK?

mixtly87 commented 3 weeks ago

@nbransby Hm, I'm not sure. After quick inspection it seems that Android SDK doesn't support the select() capability of Firestore SDK.

However I'm not sure if this library uses firestore android SDK under the hood or Firebase support is implemented from scratch (in which case it would not matter if Firebase Android SDK supports select).

nbransby commented 3 weeks ago

We depend on the android, iOS and js firebase sdks so can only add features they support

mixtly87 commented 3 weeks ago

Ok, I understand.