15

I've been stuck on this issue for so long. I just started implementing Firestore in my react-native application with react-native-firebase. I'm just following the docs [https://invertase.io/oss/react-native-firebase/v6/firestore/quick-start#reading-data] but it doesn't work for me.

This is in Android. Haven't tested in iOS yet.

I keep getting this error:

[TypeError: undefined is not a function (near '...this._firestore.native.collectionGet...')]

Here's the relevant code:

import React, {Component} from 'react';
import { firebase } from '@react-native-firebase/firestore';

export default App extends Component{
  constructor(props) {
    super(props);

    this.getData= this.getData.bind(this)
    this.getData()

    this.state = {};
  }

  async getData() {
    try {
      const querySnapshot = await firebase.firestore()
      .collection('Gyms')
      .get() //error with this

      console.log('Documents', querySnapshot.docs);

    } catch (e) {
      console.log(e);
    }
  }
}


Any help would be much appreciated!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Akshat Jain
  • 161
  • 1
  • 3

3 Answers3

16

This error occurs because the native RNFirestore module is missing.

After yarn add @react-native-firebase/firestore you need to run pod install and trigger a rebuild with react-native run-ios.

edit: installing this modules requires you to re-bundle your application in android as well. run something like react-native run-android to do that.

If you are using expo on m1 machine then first cd inside your ios bundle and then run:

arch -x86_64 pod install 
Lonare
  • 3,581
  • 1
  • 41
  • 45
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
2

This issue resolves when you re-bundle and restart android dev server

Kornelijus Sl
  • 41
  • 1
  • 4
1

If you have a good firebase / Firestore setup so it's because your queries is false, you can test with something like that:

import firestore from '@react-native-firebase/firestore';

firestore()
  .collection('collection')
  .onSnapshot((querySnapshot) => {
     console.log(querySnapshot)
  })
Dako Junior
  • 587
  • 6
  • 8