Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting undefined when using FieldValue or FirestoreAdminClient

as the title suggests I'm trying to use FieldValue and FirestoreAdminClient as follow:

const client = new admin.firestore.v1.FirestoreAdminClient();

And in another function of my server:

await db.doc("stats/users").update({
  total: admin.firestore.FieldValue.increment(1),
});

But when I run my function I get:

TypeError: Cannot read properties of undefined (reading 'FirestoreAdminClient')

I don't know what's happening and why. If you have any suggestion please share it

like image 313
Allennick Avatar asked Sep 04 '25 17:09

Allennick


1 Answers

I have been searching for this for like a whole day and found the solution from one of the firebase NodeJS snippets repositories. I know it is not in typescript so just change the import accordingly.

// for the import part
const {getFirestore, FieldValue} = require("firebase-admin/firestore");
// also, getFirestore is another import I needed and you might not so change accordingly

// for the update
await admin
 .firestore()
 .collection("Posts").doc(docId).update({
   postImages: FieldValue.arrayUnion(signedUrl),
 }).then((_) => {
    functions.logger.log("Updated the image link successfully");
 });

like image 92
Waqad Arshad Avatar answered Sep 07 '25 12:09

Waqad Arshad