无法从 React-Native-Firebase(v6) Firestore 获取数据:undefined 不是函数(靠近 '...this._firestore.native.collectionGet...')

Aks*_*ain 12 javascript firebase react-native google-cloud-firestore react-native-firebase

我已经被这个问题困住了这么久。我刚刚开始使用 react-native-firebase 在我的 react-native 应用程序中实现 Firestore。我只是在关注文档 [ https://invertase.io/oss/react-native-firebase/v6/firestore/quick-start#reading-data]但它对我不起作用。

这是在安卓中。尚未在 iOS 中测试。

我不断收到此错误:

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

这是相关的代码:

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);
    }
  }
}


Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激!

Pet*_*ron 7

发生此错误是因为缺少本机 RNFirestore 模块。

yarn @react-native-firebase/firestore您需要运行pod install并触发重建之后react-native run-ios


Dak*_*ior 1

如果您有良好的 firebase / Firestore 设置,那么这是因为您的查询是错误的,您可以使用类似的内容进行测试:

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

firestore()
  .collection('collection')
  .onSnapshot((querySnapshot) => {
     console.log(querySnapshot)
  })
Run Code Online (Sandbox Code Playgroud)