Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda