I want to have a list contains the IDs of the documents in a collection for using the id as string in comparison with something else but I couldn’t find the way to do that
I wrote the following
final firebaseid = FirebaseFirestore.instance.collection('Guests').get().then((value) {
var id = value;
print(id);
});
but I couldn’t get the documents ids
3
Answers
Try this
While Murat’s answer will get you the data of all documents, you seem to be asking for the document IDs. In that case, you’ll want:
The big difference here is that the code handles the fact that the result of calling
get
on aCollectionReference
is aQuerySnapshot
, and you’ll need to loop over itsdocs
to get each individual document. This is also shown in the Firebase documentation on getting all documents in a collection.You can get a list of all ids in a collection like this: