Skip to content

DocumentReference.get() uses wrong Firestore database when multiple databases are configured #2398

@devmaxime

Description

@devmaxime

When using the Firebase Admin SDK in Node.js with multiple Firestore databases, DocumentReference instances do not retain their originating database context.

As a result, calling .get() on a reference may silently query the wrong database, depending on which database was most recently used. This leads to confusing and inconsistent behavior.

The only way to guarantee correct behavior is to manually reconstruct the reference using the correct Firestore instance every time:

await db2.collection('users').doc(docRef.id).get();

DocumentReference should retain a reference to the Firestore instance it was created from, so that .get() always uses the correct database. At minimum, using .get() in the wrong context should throw a clear error.

Environment: Node.js 20 and "firebase-admin": "^12.2.0"
Setup: one initialized app, multiple Firestore databases via getFirestore(app, db)

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/nodejs-firestore API.needs more infoThis issue needs more information from the customer to proceed.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions