-
Notifications
You must be signed in to change notification settings - Fork 157
Description
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)