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

266
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!