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

213
Views
Modify arrays in Firebase Firestore

The Firestore database has the following field structure

images: {day: ['url1', 'url2', 'url3,] night: ['url1']}

First I would like to be able to append a value to the arrays. Did try the following:

await updateDoc(doc(firestore, FIRSTORE_COLLECTIONS.IMAGES, id), {
        [folder]: {
          [key]: arrayUnion(fileUrl)
        }

It went to the right images: path but unfortunately this just created a new array with one value and removed the ones that where there.

Secondly. If I also like to be able to create a new array in the same path with a key that does not exist can this be done and how could that be solved with this setup any ideas?

dependencies: "firebase": "^9.1.1", "react": "^17.0.2"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is what solved it:

 await updateDoc(ref, {
        [`${folder}.${key}`]: arrayUnion(fileUrl)
      });

Proper path where the arrayUnion methods is implemented. It also creates a new array if key does not exists, which is nice.

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!