从firstore集合React获取具有ID的文档

时间:2020-02-16 17:56:06

标签: reactjs google-cloud-firestore

我不知道如何在Firebase返还给我的商店阵列中获得Firestsore文档(商店)ID的属类。

    componentDidMount() {
    let response = fire.firestore().collection('shops').
    get().
    then(snapshot => {
        const data = snapshot.docs.map(doc => doc.data());
        this.setState({
            ...this.state,
            shopsArray: data
        })
    })
}

SwiftUI use relationship predicate with struct parameter in FetchRequest

1 个答案:

答案 0 :(得分:1)

要获取文档ID,请使用DocumentSnapshot.id property。像这样:

componentDidMount() {
    let response = fire.firestore().collection('shops').
    get().
    then(snapshot => {
        snapshot.docs.forEach((doc) => { console.log(doc.id); });
        ...