简体   繁体   中英

Cloud Firestore Document IDs

I'm trying to get the document Ids from a /users collection. However, I don't see an id on the objects that are being returned. How do I get the document Ids for each document with my code listed below?

Pages:

  1. AllUsers (Where I map all of the user objects to User components)

  2. ViewUser (When the user component is clicked on, I want to use this document Id here)

All Users Saga:

let allUsersData = yield documentSnapshots.docs.map(document => document.data());

Possibilities?

  • getId() (Where do I do this to add each id to each of the user objects?)

Each DocumentSnapshot (like in your documentSnapshots.docs ) has id and data() .

You're explicitly dropping the document IDs when you do this:

let allUsersData = yield documentSnapshots.docs.map(document => document.data());

To get both, stick to using DocumentSnapshot or (if you want to stick to plain old JSON objects) merge the id with the data:

documentSnapshots.docs.map(document => ({ id: document.id, ...document.data() }));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM