Ask Your Question
2

What is the method to obtain the ids of documents in a list using Flutter Firestore?

asked 2021-07-10 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-04-09 12:00:00 +0000

plato gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2021-07-10 11:00:00 +0000

Seen: 24 times

Last updated: Apr 09 '21