Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

464
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda