Somebody please help me. This is what is standing in the way of a public release of our app, and it is talking up countless hours, more than it took to develop the function in the first place.
* Background
The goal was to update the document. I was told to not auth as a standard firebase user. I should use firebase-admin instead. I was skeptical, but going with it, I am using firebase-admin/firestore to update a document from the backend.
* Bug
I can't figure out what function to use with firebase-admin/firestore to update the doc. setDoc returns as undefined, when
js source block
const { collection, query, where, updateDoc, onSnapshot, getFirestore, doc, runTransaction, setDoc } = require('firebase-admin/firestore')
called with
await setDoc((db, "cities", "LA"), invoices)
returns error
await setDoc((db, "cities", "LA"), invoices);
^
TypeError: setDoc is not a function`
Calling doc and setDoc from
const { doc, setDoc } = require("firebase/firestore")
and removing from firebase-admin/firestore returns
`@firebase/firestore/dist/index.node.cjs.js:25146
if ('_delegate' in obj) {
^
Same if only setDoc is called from firestore
Other people who had this problem but never updated their thread with a solution:
https://discord.com/channels/626375663313748008/1084079801062654023
https://discord.com/channels/626375663313748008/1088975454054141992
Solved! Go to Solution.
Figured it out, credit to DiGi on firebase discord. I was mixing the client and server apk, which I did not know was distinct. I was calling functions from the client sdk instead of instantiating classes from the server sdk and calling methods on those classes, should have consulted https://googleapis.dev/nodejs/firestore/latest/ for nodejs. Server code follows dot notation of the form db.collection().doc() rather than doc("id")
Figured it out, credit to DiGi on firebase discord. I was mixing the client and server apk, which I did not know was distinct. I was calling functions from the client sdk instead of instantiating classes from the server sdk and calling methods on those classes, should have consulted https://googleapis.dev/nodejs/firestore/latest/ for nodejs. Server code follows dot notation of the form db.collection().doc() rather than doc("id")