Search code examples
node.jsfirebasegoogle-cloud-firestore

Nodejs + Firestore: Error: Did not receive document for "..."


I'm learning firestore and while exploring I came across some strange behaviour, reducing this example to a minimum, here's what I got:

import { Firestore } from "@google-cloud/firestore";
const firestore = new Firestore({
    databaseId: "(default)"
});
async function main() {
    const document = firestore.doc('test/mydoc');
    await document.set({
        title: 'Welcome to Firestore',
        body: 'Hello World',
    });
    console.log('Entered new data into the document');

    await document.update({
        body: 'My first Firestore app',
    });
    console.log('Updated an existing document');

    const doc = await document.get();
    console.log('Read the document', doc.data());

}

Console output:

Entered new data into the document
Updated an existing document
19 | const document_1 = require("./document");
20 | const util_1 = require("./util");
21 | const logger_1 = require("./logger");
22 | /**
23 |  * A wrapper around BatchGetDocumentsRequest that retries request upon stream
24 |  * failure and returns ordered results.
                              ^
error: Did not receive document for "test/mydoc".

The data is visible in the panel, the record is indeed created He just can't get all the records. Moreover, I tried doing something like:

firestore.collection('test').get()

and it sometimes gets 1 record, sometimes 0, no connection I can't find. Although there may be more than one record in a collection

I actually copied the firestore example from the gcloud website and it doesn't work as expected


Solution

  • Resolved.

    Problem in usage bun