firebase-kotlin-sdk icon indicating copy to clipboard operation
firebase-kotlin-sdk copied to clipboard

Support for Non Default database access in Firestore

Open inderrapido opened this issue 1 year ago • 6 comments

Is there any plan to add support for accessing the non-default database in Firestore?

inderrapido avatar Nov 28 '24 15:11 inderrapido

So we not already have this?

nbransby avatar Nov 29 '24 23:11 nbransby

So we not already have this?

Unfortunately, it’s not available. We’re currently limited to connecting only to the default database.

inderrapido avatar Nov 30 '24 03:11 inderrapido

please use this template

nbransby avatar Nov 30 '24 06:11 nbransby

I have the same issue. Using a non-default database was possible until version 1.13.0, by using:

commonMain:

expect fun getFirebaseFirestore(): FirebaseFirestore

androidMain:

import com.google.firebase.Firebase
import com.google.firebase.firestore.firestore
import dev.gitlive.firebase.firestore.FirebaseFirestore

actual fun getFirebaseFirestore(): FirebaseFirestore {
    return FirebaseFirestore(native = Firebase.firestore(database = "prod-db"))
}

iOSMain:

import cocoapods.FirebaseFirestoreInternal.FIRFirestore
import dev.gitlive.firebase.firestore.FirebaseFirestore
import kotlinx.cinterop.ExperimentalForeignApi

@OptIn(ExperimentalForeignApi::class)
actual fun getFirebaseFirestore(): FirebaseFirestore {
    return FirebaseFirestore(FIRFirestore.firestoreForDatabase(database = "prod-db"))
}

However, with version 2.0.0 FirebaseFirestore was declared as internal, which leads to the error: Cannot access 'constructor(native: FirebaseFirestore): FirebaseFirestore': it is internal in 'dev/gitlive/firebase/firestore/FirebaseFirestore'.

@nbransby Can it be declared as public again? Or is there an alternate new way?

sjaindl avatar Dec 22 '24 23:12 sjaindl

Hi @nbransby i too facing this issue.

GvHarish9894 avatar Jul 06 '25 13:07 GvHarish9894

Just tried updating and ran into this issue as well. I was employing the same solution as @sjaindl to create a named database and now I can't and the SDK doesn't provide a way to do it (AFAICT).

Looks like there's a PR open to solve this but it's still open.

https://github.com/GitLiveApp/firebase-kotlin-sdk/pull/698

Any word on if this PR will merge and when it'll be available?

dominicoder avatar Jul 25 '25 07:07 dominicoder