0

I am trying to create field into Google Firestore document and everytime I am getting the following error.

Error setting document Error: 4 DEADLINE_EXCEEDED: Deadline exceeded
at Object.callErrorFromStatus (/<my-folder-path>/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
at Http2CallStream.<anonymous> (/<my-folder-path>/node_modules/@grpc/grpc-js/build/src/client.js:96:33)
at Http2CallStream.emit (events.js:215:7)
at /<my-folder-path>/node_modules/@grpc/grpc-js/build/src/call-stream.js:75:22
at processTicksAndRejections (internal/process/task_queues.js:75:11) {
  code: 4,
  details: 'Deadline exceeded',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}

Following is my sample Node script

var admin = require("firebase-admin");
var serviceAccount = require("/<my-folder-path>/<project-name>.json");
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://<project-name>.firebaseio.com"
});
let db = admin.firestore();
let citiesRef = db.collection('cities');
let setSf = citiesRef.doc('SF').set({
    name: 'San Francisco', state: 'CA', country: 'USA',
    capital: false, population: 860000,
    regions: ['west_coast', 'norcal']
}).then(obj => {
    console.log("Finished");
}).catch(err => {
    console.log('Error setting document', err);
});

Now in below script, first get() is called and then set(). Strangly this is working. so I am sure this is not related to slow internet connection or issue related to quota. Neither I am posting bulk records. Practically, I can't call get() always to create new records.

var admin = require("firebase-admin");
var serviceAccount = require("/<my-folder-path>/<project-name>.json");
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://<project-name>.firebaseio.com"
});
let db = admin.firestore();
let cityRef = db.collection('cities').doc('SF');
let getDoc = cityRef.get()
    .then(doc => {
        if (!doc.exists) {
            console.log('No such document!');
        } else {
            console.log('Document data:', doc.data());
        }
    }).then(obj => {
        let citiesRef = db.collection('cities');
        let setSf = citiesRef.doc('SF').set({
            name: 'San Francisco', state: 'CA', country: 'USA',
            capital: false, population: 860000,
            regions: ['west_coast', 'norcal']
        }).then(fin => {
            console.log("Finished");
        }).catch(err => {
            console.log('Error in set', err);
        });
    })
    .catch(err => {
        console.log('Error getting document', err);
    });
Amit Maniar
  • 1,126
  • 8
  • 10
  • 1
    If you do a web search for "firestore deadline_exceeded" you'll find lots and lots of discussion on why this error happens. – Doug Stevenson Nov 24 '19 at 18:54
  • no, it is not related to that. I went through all its answers. Read my full question. – Amit Maniar Nov 24 '19 at 18:57
  • If you are positive that it's not related to the known causes, then file a bug report with Firebase support so that they can reproduce the error and confirm. In your report, it will be helpful if you explain all the steps starting from a fresh, isolated project that reproduce the error. https://support.google.com/firebase/contact/support – Doug Stevenson Nov 24 '19 at 19:03
  • If you can't reproduce in a fresh project, then there might be something wrong with your current project, and they will escalate to engineering to see what's wrong. – Doug Stevenson Nov 24 '19 at 19:06
  • Looks like some issue with MacOS nodeJs, because working properly in Ubuntu. I will try different combinations and then file issue if required. Thanks – Amit Maniar Nov 24 '19 at 19:10
  • I use node on MacOS for this sort of thing all the time and never seen this problem. – Doug Stevenson Nov 24 '19 at 19:20

0 Answers0