Reputation: 55
I have an error as in the description. What did I do wrong? I would like all collection 'hives' documents to be displayed. Is the code that is written in the second photo correct? Or maybe I need to change something? Do I have to add a rule in 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;
Hives.vue
<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>
Upvotes: 0
Views: 257
Reputation: 317692
Firestore does not allow for collection group queries with collectionGroup()
to be scoped under a specific document. collectionGroup()
can only be used to query across all subcollections of the same name in the entire database like this:
fb.collectionGroup("hives").get()
If you just want to get a specific subcollection nested under a document, just build a reference to it:
fb.usersCollection.doc(...).collection("hives").get()
Upvotes: 2