0

This is the view of my database:

1

import React, { useState } from "react";
import { db } from "../firebase";
import { collection, Firestore, getDocs } from "firebase/firestore";

function Document() {
  const handleFetchData = async () => {

//What should I Write to get the documents from Kids collection
};

}

return (
  <div>
    <button onClick={handleFetchData}> Fetch Data </button>
  </div>
);

export default Document;

I want to get the innermost document (document of Kids collection) by just clicking on the button

2 Answers 2

1

Try once with following code:

const ref = db.collection('Price List').doc('Dry Clean').collection('Kids');
const doc = await ref.get();
Sign up to request clarification or add additional context in comments.

3 Comments

It is showing error " db.collection is not a function"
Then there must be error in initializing your db
Actually, This method was used used in firebase 8
0
var docRef = doc(
          db,
          'Price List',
          'Dry Clean',
          'Kids',
          'Kids Shirt'
        );
    
        const docSnap = await getDoc(docRef);
    
        if (docSnap.exists()) {
          console.log('Document data:', docSnap.data());
        } else {
          // doc.data() will be undefined in this case
          console.log('No such document!');
        }

Actually the correct solution is this after firebase 9

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.