firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.75k stars 872 forks source link

Document references from another DB cause error logs #8166

Open tzappia opened 1 month ago

tzappia commented 1 month ago

Operating System

macOS 14.4.1

Browser Version

Chrome/123.0.6312.124

Firebase SDK Version

10.11.0

Firebase SDK Product:

Firestore

Describe your project's tooling

Angular 17 app

Describe the problem

When using imported production data in a dev environment with an app using the Firebase emulators, I get the following error in the browser JavaScript console:

@firebase/firestore: Firestore (10.11.0): Document users/<documentId> contains a document reference within a different database (<databaseName>/(default)) which is not supported. It will be treated as a reference in the current database (demo-project/(default)) instead.

This appears to have no functional impact (I looked at the source Firebase code and the only action taken for this reference check is to log an error.) When loading a page with a long list of documents, this causes my Chrome JavaScript console to grind to a halt and become pretty unresponsive (there are many, many instances of this error log.)

Since this is more informational than an actual error, ideally this log would just be removed and be covered in documentation if necessary. In addition, if there are any tips for importing production data an an emulated environment and having all document references converted appropriately, I'd be happy to learn about it!

There is a comment in the code where the error is logged // TODO(b/64130202): Somehow support foreign references. but this bug report is about the error log and not asking for support for foreign references.

Steps and code to reproduce issue

  1. Export Firestore data from a production database.
  2. Import that data when launching an app that uses the emulators with the --import flag.
  3. In the development environment app that uses the emulator, query documents that include a Reference in the document data.
dconeybe commented 1 month ago

Hi @tzappia. Thank you for reporting this issue. I'm able to reproduce it and I can see how it would be a nuisance.

Here are the steps that I followed:

  1. Extract firestore_export_data.zip to a directory on your local computer.
  2. Start the Firestore emulator: firebase emulators:start --only firestore --import 2024-04-19T16:22:17_20757 (the path to --import is the directory that was created upon extracting the zip file).
  3. Run a query in the collection EmulatorImportIssue8166.

Expected Results: No warnings are logged.

Actual Results: The following warning is logged to the console: Document EmulatorImportIssue8166/DocA contains a document reference within a different database (dconeybe-testing/(default)) which is not supported. It will be treated as a reference in the current database (foo-bar-baz/(default)) instead.

Here is some sample code to run the query:

const db = getFirestore();
const collectionRef = collection(db, "EmulatorImportIssue8166");
const snapshot = await getDocs(collectionRef);
for (const documentSnapshot of snapshot.docs) {
  console.log(`Document: ${documentSnapshot.id}: ${JSON.stringify(documentSnapshot.data())}`);
}

Attachments:

dconeybe commented 1 month ago

I've logged b/335854401 to track this request internally. Note, however, that I can't make any promises as to if or when we will fix this. But we will reply back if there is any progress.