You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用node-firestore-backup-restore备份Firestore仅读取单个文档求助

Troubleshooting Tips for node-firestore-backup-restore Only Reading One Document

Hey Dave, sorry to hear you're stuck with this odd issue—since your iOS app can access all the documents without a problem, the root cause is almost certainly tied to how the backup script interacts with Firestore. Here are some actionable steps to debug and fix this:

  • Double-Check Firebase Admin Service Account Permissions
    Verify the service account your script uses. If it’s assigned a restricted custom role (instead of a broad one like Cloud Datastore User or Editor), it might only have access to that single document. Even if you think permissions are correct, reassigning the role and retrying can rule out IAM propagation delays that might be blocking access to other docs.

  • Inspect the Script’s Query Logic
    Dig into the node-firestore-backup-restore source code, specifically the section that fetches collection documents. Look for:

    • Accidental filtering: Is there a hardcoded where() clause that’s unintentionally limiting results to one document?
    • Document existence checks: Some scripts mark docs as "non-existent" if they don’t have top-level fields (even if they have subcollections). If your missing docs only contain subcollections and no root fields, the script might be incorrectly skipping them.
    • Pagination gaps: Firestore returns docs in batches (max 1000 per request). If the script doesn’t handle pagination with cursors, it might stop after the first batch—but this is less likely if you’re only getting one document total.
  • Add Verbose Logging to Catch Hidden Errors
    Modify the script to log detailed info when fetching each document. For example, in the document retrieval section, add:

    docRef.get().then(snapshot => {
      if (!snapshot.exists) {
        console.warn(`Document ${docRef.id} marked as missing — snapshot details:`, snapshot);
      } else {
        // Process the document as usual
      }
    }).catch(err => {
      console.error(`Failed to fetch document ${docRef.id}:`, err);
    });
    

    This might reveal hidden issues like permission denials for specific docs or unexpected data types the script can’t handle.

  • Update Dependencies for Compatibility
    Outdated versions of firebase-admin (the SDK the script relies on) can have bugs with newer Firestore features (like timestamp fields, special characters in document IDs, or nested subcollections). Try updating the firebase-admin entry in the script’s package.json to the latest stable version, then run npm install and retry the backup.

  • Test Individual Document Fetches
    Write a tiny standalone script to fetch one of the "missing" documents directly using the same service account. For example:

    const admin = require('firebase-admin');
    const serviceAccount = require('./your-service-account-key.json');
    
    admin.initializeApp({
      credential: admin.credential.cert(serviceAccount)
    });
    
    const db = admin.firestore();
    db.collection('your-target-collection').doc('problem-document-id').get()
      .then(snapshot => {
        console.log('Snapshot exists:', snapshot.exists);
        console.log('Document data:', snapshot.data());
      })
      .catch(err => console.error('Fetch error:', err));
    

    If this script can fetch the document, the issue is definitely in the node-firestore-backup-restore code’s logic. If it can’t, you’ll get a clear error message pointing to the root cause (like invalid permissions or malformed document paths).

内容的提问来源于stack exchange,提问作者David Mrozinski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:31:51