Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore Getting documents id from collection

I'm trying to retrieve my documents with id but can't figure it out.
Currently I retrieve my documents like this :

const racesCollection: AngularFirestoreCollection<Races> = this.afs.collection('races'); return racesCollection.valueChanges(); 

I do get my documents list perfectly, however there is no doc id with them.

How can I retrieve it for each document ?

like image 379
DominikG Avatar asked Oct 24 '17 00:10

DominikG


People also ask

How do I find the number of documents in a collection firestore?

If you need a count, just use the collection path and prefix it with counters . As this approach uses a single database and document, it is limited to the Firestore constraint of 1 Update per Second for each counter.

Is firebase document ID unique?

Correct, it is extremely unlikely, but not guaranteed. Same as UUIDs, and GUIDs (2^122 combinations).


1 Answers

For angular 8 and Firebase 6 you can use the option id field

      getAllDocs() {            const ref = this.db.collection('items');            return ref.valueChanges({idField: 'customIdName'});       } 

this adds the Id of the document on the object with a specified key (customIdName)

like image 177
Ivan Tarskich Avatar answered Sep 21 '22 01:09

Ivan Tarskich