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

259
Views
firebase - get all snapshots from list of refrences

firestore database in user collection:

id1: {
    name: 'test',
    friends: [
        users/id2,
        users/id3
    ]
}

id2: {...}
id3: {...}

I'm trying to receive the snapshots of all references in friends array. (myRef si a reference to users/id1)

const refFriends = (await getDoc(myRef)).data().friends;
const friendsSnaps = await getDocs(refFriends);
console.log(friendsSnaps);

When running, I get this error.

[Unhandled promise rejection: FirebaseError: Expected type 'pc', but it was: an array]

Any ideas?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The getDocs() takes a Query as paramater and not an array of DocumentReference. You can map an array of getDoc() from 'friends' array and use Promise.all() to fetch them at once:

const refFriends = (await getDoc(myRef)).data().friends;

const friendsSnaps = await Promise.all(refFriends.map((f) => getDoc(f)));

Alternatively, you could map array of document IDs and then use in operator to fetch the documents in a single query but this works only when you have up to 10 friends.

about 4 years ago · Santiago Trujillo 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!