TypeError:_firebase__WEBPACK_IMPORTED_MODULE_10 __。usersCollection.doc(...)。collectionGroup不是函数

WHO

我在描述中有一个错误。我做错了什么?我希望显示所有收集的“蜂箱”文件。第二张照片中写的代码正确吗?还是我需要改变一些东西?我必须在Firebase中添加规则吗?

在此处输入图片说明

在此处输入图片说明

index.js

import * as fb from '../firebase';

const store = new Vuex.Store({
    state: {
        hives: [],
    },

    mutations: {
        setHives(state, val) {
            state.hives = val;
        },
    },

    actions: {
        async getHives() {
            await fb
                .collectionGroup('hives')
                .get()
                .onSnapshot((snapshot) => {
                    let hivesArray = [];

                    snapshot.forEach((doc) => {
                        let hive = doc.data();
                        hive.id = doc.id;

                        hivesArray.push(hive);
                    });

                    store.commit('setHives', hivesArray);
                });
        },
    },
});

export default store;

荨麻疹

<template>
    <ul class="content__list" v-if="hives.length">
        <li class="content__item">
            <p>ID</p>
            <p>Nazwa pasieki</p>
        </li>
        <li class="content__item" v-for="hive in hives" :key="hive.id">
            <p class="content__apiary-name">
                {{ hive.hiveId }}
            </p>
            <p class="content__apiary-name">
                {{ hive.apiary.apiary }}
            </p>
        </li>
    </ul>
</template>

<script>
export default {
    created() {
        this.getHives();
    },

    methods: {
        getHives() {
            this.$store.dispatch('getHives');
        },
    },
};
</script>
道格·史蒂文森

Firestore不允许将集合组查询的collectionGroup()范围限制在特定文档下。collectionGroup()只能用于查询整个数据库中同名的所有子集合,如下所示:

fb.collectionGroup("hives").get()

如果只想将特定的子集合嵌套在文档下,则只需建立对其的引用即可:

fb.usersCollection.doc(...).collection("hives").get()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档