Home > front end >  React Native Unable to fetch multiple documents data from Firebase firestore
React Native Unable to fetch multiple documents data from Firebase firestore

Time:08-04

Please Check the image, I have not get the second part

App.js File this is App.js file, Please check the below code and correct me I don't have any idea how to solve this issue. Thank you in advance.

.doc("2E3kDAa0QzqoQuoBK1T9", "vROxKUSgcNWwlt7cDEKV") on this line I get the issue.

import React, { useState, useEffect } from "react";
import { View, Text } from 'react-native';
import firestore from '@react-native-firebase/firestore';
function App() {
  const [myData, setMyData] = useState(null);
useEffect(() => {
    getDatabase();
  }, []);
const getDatabase = async () => {
try {
      const data = await firestore()
        .collection('myCollection')
        .doc("2E3kDAa0QzqoQuoBK1T9", "vROxKUSgcNWwlt7cDEKV")
        .get();
      setMyData(data._data)
    } catch (err) {
      console.log(err);
    }
  };
  return (
    <View>
      <Text>First:-{myData ? myData.name : 'Loading...'}</Text>
      <Text>Second:-{myData ? myData.secondData : 'Loading...'}</Text>
    </View>
  );
}
export default App;

CodePudding user response:

This doesn't work:

.doc("2E3kDAa0QzqoQuoBK1T9", "vROxKUSgcNWwlt7cDEKV")

If you check the API docs for CollectionReference.doc it expects:

doc(documentPath?: undefined | string): DocumentReference<>;

So you can pass in a single document ID or path, not multiple.


If you want to return multiple documents by their ID, you can use th in query operator on the FieldPath.documentId() to do so for up to 10 values. If you have more values, you'll need to retrieve them in batches of up to 10 and merge them in your application code.

  • Related