Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

467
Views
Firestore Admin SDK FieldValue.increment returning wrong value

I am getting the following error when using FieldValue.increment when running a cloud function wrapped with firebase-functions-test:

Value for argument "data" is not a valid Firestore document.

Couldn't serialize object of type "NumericIncrementTransform" (found in field "count").

Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator).

Here is the code that is wrapped:

  // `functions` is the firebase-functions module 
  // `firestore` is an initialized FirebaseFirestore.Firestore instance pointing to the 
  //  Firestore emulator
  const { functions, firestore } = require('../../firebase');
  const getTestRelationshipRefs = require('../utils/getTestRelationshipRefs');
  const admin = require('firebase-admin');

  module.exports = functions.firestore
    .document('orgs/{orgId}/tests/{testId}')
    .onUpdate(async (change, context) => {
      const beforeData = change.before.data();
      const afterData = change.after.data();

      const relationshipRefs = getTestRelationshipRefs(afterData, context.orgId);
      const batch = firestore.batch();
   
      if (beforeData.active === false && afterData.active === true) {
        for (const ref of relationshipRefs) {
          batch.set(
            ref,
            { count: admin.firestore.FieldValue.increment(1) },
            {
              merge: true,
            }
          );
        }
      }

There are other questions out there that seem similar such as: Firebase cloud function - Unhandled error Error: Update()

But it looks like I am doing the posted solution.

There are other posts I have seen that indicate this can be the result of having different versions of @google-cloud/firestore in the dependency tree. I don't think that is it in this case but would be delighted to be wrong.

All of the firebase related dependencies in my package.json are:

"firebase-admin": "^9.5.0",
"firebase-functions": "^3.13.2",
"firebase-tools": "^9.6.1",
"@firebase/rules-unit-testing": "^1.2.5",
"firebase-functions-test": "^0.2.3",

Here is the output of npm ls @google-cloud/firestore

└─┬ firebase-admin@9.5.0
  └── @google-cloud/firestore@4.9.8 

Why is admin.firestore.FieldValue.increment returning the wrong value?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!