Can a snapshot be taken of an auto-generated ID document in FireStore?

Currently, I am working on developing both a mobile app and web app for my Final Year Project. As someone relatively new to Firestore, I am using a single instance of it to store data.

When a customer registers through the mobile app, their information gets stored in the "users" collection with a unique ID representing each individual customer [Document]. This is further divided into sub-collections like "profile" and "orders" to store specific details.

After a successful registration, here's how the current Firestore setup looks:

While attempting to display the "Profile" sub-collection in my web application, I've managed to do so but only for a single user at a time.

created() {
        db.collection('users/FbkKmQMaGYY2gErEneImmjUMvRt1/profile').onSnapshot((snapshotChange) => {
            this.Users = [];
            snapshotChange.forEach((doc) => {
                this.Users.push({
                    key: doc.id,
                    fname: doc.data().fname,
                    lname: doc.data().lname,
                    username: doc.data().username,
                    mail: doc.data().mail,
                    phone: doc.data().phone,
                    address: doc.data().address,
                    img: doc.data().img,
                })
            });
        })
    },

My query is: Are there any methods that would allow me to retrieve ALL instances of the "Profile" sub-collection (as shown in the image), enabling me to display them in my Web Application for administrative purposes?

Thank you in advance for your assistance! :)

Answer №1

To display profiles from all users, you can utilize a collection group query as shown below:

db.collectionGroup('profile').onSnapshot((snapshotChange) => {

You don't need to make any changes in the rest of your code.

This query will retrieve all documents under collections named profile.

Keep in mind that there is no direct way to specifically access profile collections under /users, so it's important to ensure your collection names are distinct and descriptive enough.

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

Gain access to PowerBI reports effortlessly without the need to input any credentials

Seeking guidance on calling Power BI reports from an ASP.NET C# web application while passing credentials, specifically without utilizing Azure AD. Access has been granted to certain users in the Power BI Service workspace with view permissions. We aim t ...

What is the best method to pass a JavaScript file array to a Node.js server?

Is it possible to transfer data from a Javascript file linked to an HTML page to a Node.js file on a post route without displaying it on the HTML page? If so, what is the best way to accomplish this? ...

Switching Next.js route using pure JavaScript

Currently, I am facing a challenge in changing the route of a Next.js application using vanilla Javascript. In order for the code to be compatible with Chrome Dev Tools, I cannot dynamically change the route with Next.js and instead must find a solution us ...

DataTables.js, the powerful JavaScript library for creating interactive tables, and its compatible counterpart

I'm currently making some changes to a dynamic table that require enabling a vertical scroll bar. As a result, I need to implement this vertical scroll bar mechanism on an existing table. The code in our project utilizes dataTables.js version 1.5.2 ...

Is there a way to achieve the same task with Ajax?

Hey there, I am new to the world of JavaScript and AJAX. I have been reading about how to convert a client-side JavaScript variable into a server-side PHP variable by using AJAX. Can someone please provide me with a code snippet using AJAX for this purpose ...

Effortlessly switching classes in JavaScript for seamless transitions

I'm currently working on an animation project where I want the title to be visible on the page initially, and then slowly fade away as you scroll down, with a subtitle fading in right after. While I've managed to get the title part working, I&apo ...

Sending form data using Node.js

Is there a way to send input form data as part of a URL in Node.js? Below is an example code snippet demonstrating this. app.get('/', (req, res) => { res.render('index'); }); app.post('/scrape', function(req, res){ ...

How to Extract a Link from JSON Data in React Native

My JSON data is formatted like this: orderData:"<p>Key VVV: 6326233</p> <p>Download link <a title=\"Movie\" href=\"https://play.google.com/store/movies/details/The_Angry_Birds_Movie_2?id=O_RbjOHHpIs&hl=en\" t ...

An error occurred while trying to update with Webpack Dev Server: [HMR] Update failed due to an issue fetching the update manifest,

I encountered an issue in the browser console while attempting to live reload / HMR on Webpack. The error arises after saving a file following a change. [HMR] Update failed: Error: Failed to fetch update manifest Internal Server Error Could the failure b ...

I'm having trouble mocking the image import correctly when trying to pass a test using jest with next.js. Why am I encountering this error?

Having some trouble passing a test with Jest in Next.js. The imported image doesn't seem to be mocked by Jest, and I can't figure out what's missing. Followed all the steps in the Next.js documentation. The fileMock.js is located at <rou ...

Discovering the optimum route within a 2D array given specific limitations using Dynamic Programming

Hey, I have a query related to dynamic programming (dp) that goes like this: Input: A 2D array of numbers Output: The maximum sum of a path from (0,0) to (n-1,n-1) with the following conditions: You can only move down and right i.e. from (A[i-1][j]) t ...

Valums file-uploader: Restricting file uploads based on user's credit score

Currently utilizing the amazing file uploader by Valums, which can be found at https://github.com/valums/file-uploader One feature I am looking to incorporate is a limit based on the user's account balance. The initial image upload is free, so users ...

Transferring event arguments to JavaScript in ASP.NET C# through OnClientClick

Currently, I have an asp button on my webpage. In the code behind within the Page_Load method, I am assigning some JavaScript calls in the following manner. btnExample.OnClientClicking = "functionOne(1,2);"+"function2()"; However, I am encountering a pro ...

It appears that using JQuery's .when and .done functions may result in the code executing before the script has finished loading

Since updating the hard-coded <script> with JQuery promises, I have been encountering these errors frequently: https://i.stack.imgur.com/xkWAk.png The issue seems to be inconsistent in replicating. Sometimes, the error occurs while loading the page ...

Error encountered in Typescript: SyntaxError due to an unexpected token 'export' appearing

In my React project, I encountered the need to share models (Typescript interfaces in this case) across 3 separate Typescript projects. To address this, I decided to utilize bit.env and imported all my models to https://bit.dev/model/index/~code, which wor ...

Transfer information from a Vue function to an external JSON document

I would like to store the data for my Vue project in an external JSON file instead of within the Vue function itself. I attempted to retrieve data from an external file using the code below, but encountered issues, possibly due to a conflict with the "ite ...

Issue with Sliding Transition in React Material UI Drawer Component

I developed a custom drawer component for my React application const CustomSidebar = () => { return ( <Drawer open={drawerOpen} onClose={() => setDrawerOpen(false)} > <Box> <Navigator / ...

Changing the route in Vue2 depending on the value stored in the store

I have a scenario where I need to dynamically change the route of my components based on a value stored in the vuex store. There are multiple template files located in separate directories (template1, template2 etc). The template id is retrieved from the d ...

What is the best way to pass props down to grandchildren components in React?

I'm trying to pass some props from a layout to its children. The issue is, it works fine when the child component is directly nested inside the layout, but it doesn't work when the child component is wrapped in another element like a div. Exampl ...

Learn the process of generating an array from a computed property array field in Vue

I have a computed property in my VueX store that fetches data like this: computed: {...mapGetters(["allCategories"])}, Each category in this.allCategories has an ID and a name: { "id": "123", "name": "Foo" } I want to extract the names from allCategor ...