It is a function to add new data if it does not exist by referring to existing data and update data if it exists. It works well, but after an hour gRpc error occurs. Details below:
Error: No connection established
at Http2CallStream.<anonymous> (D:\zyleTcpServer\node_modules\@grpc\grpc-js\build\src\call.js:68:41)
at Http2CallStream.emit (events.js:215:7)
at D:\zyleTcpServer\node_modules\@grpc\grpc-js\build\src\call-stream.js:75:22
at processTicksAndRejections (internal/process/task_queues.js:75:11)
---------------------------------------------
at BunWrapper.Readable.on (D:\zyleTcpServer\node_modules\bun\node_modules\readable-stream\lib\_stream_readable.js:729:33)
at D:\zyleTcpServer\node_modules\@google-cloud\firestore\build\src\index.js:920:26
at new Promise (<anonymous>)
at Firestore._initializeStream (D:\zyleTcpServer\node_modules\@google-cloud\firestore\build\src\index.js:881:16)
at D:\zyleTcpServer\node_modules\@google-cloud\firestore\build\src\index.js:1017:28 {
code: 14,
details: 'No connection established',
metadata: Metadata { internalRepr: Map {}, options: {} }
}
And here is my code
<code>
const docName = `${vin}-${dtc}`; //make doc
const ebsRef = db.collection('events').doc(docName);
await db.runTransaction((t) => t.get(ebsRef)
.then(async (doc) => {
if (!doc.exists) {
return t.set({
startDatetime: firebase.firestore.FieldValue.serverTimestamp(),
endDatetime: firebase.firestore.FieldValue.serverTimestamp(),
description: dtcData.description,
dtcCode: dtc,
eventType: brokenType,
scannerCode: dtcData.scanner,
vin,
});
}
return t.update(ebsRef, {
status: (rawDtc.status === '08' ? 2 : 1),
endDatetime: firebase.firestore.FieldValue.serverTimestamp(),
});
</code>
<br>
Is there a problem with my source code? How can i fix it..?