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

271
Vistas
Firestore - Store a property id is reference type by firestore Batch transaction

I trying to store data content reference type by batch transaction, then I got an exception:

Function WriteBatch.set() called with invalid data. Unsupported field value: a custom object (found in document orders/OC9dZErupEhPsamp8QEd)

Is there a way we can use batch transaction to store reference type?

this is my code:

batch.update(orderRef, {
    userId: firestore.doc(userId),
});
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Normaly update() use to update existing firestore data. Review firestore docs for the same. In that given example they are updating population by increments of value or with new population number but before passing it in each update function values are stored in one cost value if it is not static value. as Asked by @dharmaraj please edit your questions by posting with full code you can also read given firestore documentation for your own studies.

    import firebase from "firebase/app";  
    const app = firebase.initializeApp({});
     const firestore = app.firestore(); 
    const batch = firestore.batch(); 
    const newUserId = firestore.doc(userId);
    batch.update(orderRef, {
     userId: newUserId,
    });

Log newUserId value and see what are you getting into it.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can't store the reference object that doc() returns, it's an object that may have circular references and functions in it. doc() is not the id of the document. If you want to get the id (which is a string), then:

const newUserId = firestore.doc(userId).ref.id;
batch.update(orderRef, {
 userId: newUserId,
});

about 4 years ago · Juan Pablo Isaza Denunciar

0

I don't know why batch validate input should be a pure object. I tried to push reference type id inside nested object then it work well, yeah I know it already is a trick, but it work.

change:

batch.update(docRef, {
  user: firestore.collection('users').doc(userId)
})

to:

batch.update(docRef, {
  user: {
    id: firestore.collection('users').doc(userId)
  }
})
about 4 years ago · Juan Pablo Isaza Denunciar
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