To obtain the ids of documents in a list using Flutter Firestore, you can use the .documentID
property of a Firestore document. Here's an example code snippet:
Firestore.instance
.collection('myCollection')
.getDocuments()
.then((QuerySnapshot snapshot) {
List<String> documentIds = [];
snapshot.documents.forEach((DocumentSnapshot document) {
documentIds.add(document.documentID);
});
print(documentIds); // prints a list of the document ids
});
In this code, we're using the getDocuments()
method to retrieve all the documents in the collection called myCollection
. Then, we're iterating over each document using a for-each loop and adding its documentID
value to a list called documentIds
. Finally, we're printing out the list of document ids.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-07-10 11:00:00 +0000
Seen: 24 times
Last updated: Apr 09 '21
How can I convert a Document in Python?
What is the method for creating a subcollection in Firebase Firestore?
What is the method of using relative position in CSS?
How to search for data in a subcollection of Firestore using a field from the main document?
What is the method to immediately modify the title of a React page upon loading?
What types of document IDs are available for the documents in the DocuSign API?
Does fetching a document from Firestore also retrieve the collections contained within it?