Firestore get DocumentSnapshot's field's value

后端 未结 5 576
盖世英雄少女心
盖世英雄少女心 2021-02-02 09:10

If I have a Firebase Firestore database which I have retrieved a DocumentSnapshot for the document corresponding to the collection on the right and stored in a

5条回答
  •  生来不讨喜
    2021-02-02 09:47

    you can use get method to get value of a field

    String username = (String) document.get("username");  //if the field is String
    Boolean b = (Boolean) document.get("isPublic");       //if the field is Boolean
    Integer i = (Integer) document.get("age")             //if the field is Integer
    

    checkout the doc for DocumentSnapshot

提交回复
热议问题