There was an error: TypeError - The function collectionGroup cannot be called on the object _firebase__WEBPACK_IMPORTED_MODULE_10__.usersCollection.doc

I encountered an issue described above. Can someone help me identify what went wrong? My goal is to display all documents in the 'hives' collection. Is the code snippet shown in the second image correct? Or do I need to make some modifications? Should I include a rule in Firebase?

https://i.sstatic.net/nnb2F.png

https://i.sstatic.net/L2HfK.png

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>Apiary Name</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>

Answer №1

Firestore prohibits the use of collection group queries with collectionGroup() restricted to a specific document. Instead, collectionGroup() can only be utilized for querying across all subcollections with the same name throughout the entire database, as shown below:

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

If you simply wish to access a particular subcollection nested under a document, you can achieve this by constructing a reference to it as follows:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

steps for setting up firestore database

Hey there, I'm trying to retrieve data from Firestore within a cloud function. To initialize Firebase, I have a file called firebase.ts: import * as admin from "firebase-admin"; import { getFirestore } from "firebase-admin/firestore&quo ...

Error encountered with nested v-for in Vue.JS causing null and undefined values to be thrown

Question Conclusion: A Vue component I am working on has the following data setup: conversations: null, currentConversation: null, There is a method that runs on mounted() to retrieve the user's conversations: /** * Method to retrieve the user&ap ...

Trouble with image uploads on the Express.js platform

Within my application, I've encountered an issue with uploading images to the public/images folder. Previously, everything was functioning properly, but now I'm facing a problem. Although I receive a success message indicating that the image has ...

What is the best way to delete a specific date from local storage using Angular after saving it with a key

I'm attempting to clear the fields in my object (collectionFilter) from local storage using localStorage.removeItem('collectionFilter'). All fields are removed, except for the date fields. Please note that I am new to JavaScript and Angular. ...

Inject the content into the DIV tag retrieved from the source

I am working on a website layout that consists of a left panel and a content div on the right. Currently, when a user clicks on a link in the left panel, a JavaScript Ajax call is made to load the corresponding content into the div tag named 'content& ...

Developing a versatile tool to eliminate duplicate items from arrays in JavaScript

Currently, I am in the process of developing a generic utility function that can eliminate duplicates from an array in JavaScript. The snippet below showcases the code where the desired outcome is successfully achieved. My goal is to transform this into ...

Error message indicating a problem with the locator By.linkText that contains dots in Selenium: TypeError - Invalid locator

I've searched through other resources for solutions, but I can't find anything that addresses my specific issue. The error message I'm encountering is TypeError: Invalid locator. Here's a snippet of my code (where I suspect the problem ...

What is the best way to update a local variable in JavaScript using Ajax requests?

function validate_authentication(){ var is_authenticated = false; $.ajax({ type: "POST", url: "/account/islogin/", data: "", async: "false", success: function(data) { if (data == "null") { ...

Is it possible to make each letter on a page a different color using JavaScript? I've noticed that there is always an additional set of span tags before each opening tag on the page

Page hosted using Google Drive Within the JS code: var doc_part = false; //denotes if a character is not part of the visible document var page_body; //function to generate random rgb values function randomInt(max, min) { return Math.floor((Math.ran ...

Having some trouble with node.js and the fs module when checking if a file exists. Let

I'm a bit confused about the various methods in Node.js to check if a file exists using fs(). One option is to use fs.readFile(): fs.readFile('somefile.html', function (err, data) { if (err) { /* file doesn't exist */ } else { /* ...

Vue 3 Composition API not triggering update on reactive object after @click event

It seems that I am encountering an issue with the Vue Composition API related to working with and updating reactive objects. Take a look at the code snippet below. It appears that the click event should update the {{colors}} output in the template when a ...

Scope challenges with making multiple rest calls in Angular.js

As a beginner in Angular.js, I am facing an issue with $scope not receiving additional value from one of two $resource rest calls. Below is the code snippet: controller: function ($scope, $modalInstance, $route) { $scope.server = {} ...

How can I securely store passwords for web scraping with Puppeteer to ensure maximum safety?

Looking for advice on scraping a website that requires login. The current code saves username and password in a config JSON file, which poses a security risk if the file is accessed by unauthorized individuals. Is there a more secure method, such as encr ...

Experiencing a problem with the bundle.js file in Angular Universal

My Angular build is giving me this error in the web browser: Uncaught SyntaxError: expected expression, got '<' in bundle.js When I run the command npm run dev:ssr, no errors are generated. However, when I try to access the application, the ...

Troubleshooting: Scope not updating in AngularJS xeditable typeahead

Currently, I am utilizing the angular xeditable typehead directive to display an autocomplete dropdown. The data is being retrieved from a JSON file on the page and utilized in the jso array for e-typeahead functionality. When typing into the input field, ...

Creating an array of logos in ReactJS with the help of TailwindCSS

After seeing multiple implementations of this feature, I find myself struggling to search for a solution. I can only access the HTML and CSS through inspecting elements, wondering if others are facing the same issue as me. Typically, we aim to implement t ...

inject a $scope object into a view when a button is clicked

Right now, I am using an array as a $scope object $scope.data { item1: "Value", item2: "Value Alt" } Every item corresponds to a form input with a default value. My goal is to create a new form from the same data set upon an ng-click event while main ...

Quantities with decimal points and units can be either negative or positive

I need a specialized input field that only accepts negative or positive values with decimals, followed by predefined units stored in an array. Examples of accepted values include: var inputValue = "150px"; <---- This could be anything (from the input) ...

Activate the audit command for the npm enterprise registry

I'd like to know how to activate the npm audit command in my npm enterprise registry. Whenever I attempt to run the npm audit command, I encounter the following error: { "error": { "code": "ENOAUDIT", "summary": "Your configured registry ( ...

Discovering the reason behind a DOM element's visual alteration upon hovering: Where to start?

Visit this page, then click on the next button to navigate to the time slots section. As you hover over any time slot, you will notice a change in appearance. Despite inspecting Chrome's developer tools, I was unable to locate a style with a hover dec ...