How to list subcollections in a Cloud Firestore document

后端 未结 3 1348
名媛妹妹
名媛妹妹 2020-11-22 07:59

Say I have this minimal database stored in Cloud Firestore. How could I retrieve the names of subCollection1 and subCollection2?

ro         


        
3条回答
  •  执念已碎
    2020-11-22 08:11

    It seems like they have added a method called getCollections() to Node.js:

    firestore.doc(`/myCollection/myDocument`).getCollections().then(collections => {
      for (let collection of collections) {
        console.log(`Found collection with id: ${collection.id}`);
      }
    });
    

    This example prints out all subcollections of the document at /myCollection/myDocument

提交回复
热议问题