How to get value of some field in firebase firestore android?

前端 未结 3 1834
深忆病人
深忆病人 2020-12-05 16:24

Like upper question, i want to get value of some field in firebase firestore instead of all document with DocumentSnapshot

like this in SQL SE

相关标签:
3条回答
  • 2020-12-05 16:39

    The Cloud Firestore client-side SDKs always read and returns full documents. There is no way to read a subset of the fields in a document.

    You can retrieve the entire document, and then process the DocumentSnapshot to just use the fields you're interested. But this means you're using more bandwidth than needed. If this is a regular occurrence for your app, consider creating a secondary collection where each document contains just the fields you're interested in.

    0 讨论(0)
  • 2020-12-05 16:50

    try this code:

    //set a global variable
    dataList: Array<any>;
    
    
    const dataCollection = firebase.firestore().collection('data');
    dataCollection.get(query => {
    query.forEach(docs => {
    this.dataList.push({id: doc.id, data:doc.data()});
      })
    })
    
    0 讨论(0)
  • 2020-12-05 16:54

    Firestore can read single field value. Firebase guides looks like didn't show these simple method.

    For example:

    [android]
    
    String value = document.getString("col_1");
    
    
    [node.js]
    
    const value = doc.data().col_1
    
    0 讨论(0)
提交回复
热议问题