React-native-firebase: firestore get API not working

Created on 7 Apr 2019  路  18Comments  路  Source: invertase/react-native-firebase


Issue


I am using RNFirebase for interacting with my firestore database. While I am able to update and create the documents via SET API, I am not able to do a GET on the document reference. While there is no error, there is no result as well.

This works:
this.ref = firebase.firestore().collection('user').doc(this.state.user.phoneNumber);
this.ref.set({
name: this.state.name
}, {merge: true})

This does not works (console log not present):
this.ref = firebase.firestore().collection('user').doc(this.state.user.phoneNumber);

this.ref.get()
.then(doc => {
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data());
}
})
.catch(err => {
console.log('Error getting document', err);
});


Project Files






iOS

ios/Podfile:

  • [ ] I'm not using Pods
  • [ ] I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A

Android

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->

Environment

  • Platform that you're experiencing the issue on:

    • [ ] iOS

    • [ ] Android

    • [ ] iOS but have not tested behavior on Android

    • [x] Android but have not tested behavior on iOS

    • [ ] Both

  • If known, the version of the platform are you experiencing the issue on:

    • ADD_SOMETHING_HERE e.g. iOS 10 or Android API 28

  • Operating System:

    • [ ] MacOS, version: N/A

    • [x] Windows, version: N/A

    • [ ] Other, please specify: N/A

  • Build Tools:

    • Visual studio code

  • React Native version:

    • react-native-cli: 2.0.1 react-native: 0.59.2

  • React Native Firebase library version:

    • "react-native-firebase": "^5.2.3",

  • Firebase module(s) you're using that has the issue:

    • [x] N/A

    • [ ] Authentication

    • [ ] Analytics

    • [x] Cloud Firestore

    • [ ] Cloud Messaging (FCM)

    • [ ] Crashlytics

    • [ ] Dynamic Links

    • [ ] Functions Callable

    • [ ] In App Messaging

    • [ ] Indexing

    • [ ] Invites

    • [ ] Instance ID

    • [ ] ML Kit

    • [ ] Notifications

    • [ ] Performance Monitoring

    • [ ] Realtime Database

    • [ ] Remote Config

    • [ ] Storage

  • Are you using TypeScript?

    • [ ] No

    • [ ] Yes, version: N/A

  • Are you using Expo, e.g. ExpoKit?

    • [x] No

    • [ ] Yes, I've _not_ ejected

    • [ ] Yes, but I have ejected to ExpoKit

    • [ ] Yes, but I have ejected to vanilla React Native

    • Expo version: N/A




Think react-native-firebase is great? Please consider supporting the project with any of the below:

Most helpful comment

馃憢 hey - thanks for the report. v5.3.0 is now published on NPM which fixes this issue.

Please see the change log for more info & upgrade steps.

All 18 comments

I feel you, I've been having the same problem for the last couple of days. I am sure they already know this, I was checking our their twitter and saw this tweet so I gave it a go.

Apparently it's still a release candidate but it works now. Just update to version 5.3.0

it is not published yet it is still WIP but will be shortly per this:

https://github.com/invertase/react-native-firebase/pull/2033#issuecomment-480491511

Just published 5.3.0-rc1 if you'd like to switch - this will be the full release - I just need to add docs, migration notes & update the starter before I can switch it over.

NM my comment on other thread, I will get it. Thanks!

No worries; if you need to know which versions of dependencies etc; you can use the testing app as a reference for now: https://github.com/invertase/react-native-firebase/tree/%40salakar/v5/v5.3.x/tests (ios/Podfile for ios & android/app/build.gradle for Android)

Just published 5.3.0-rc1 if you'd like to switch - this will be the full release - I just need to add docs, migration notes & update the starter before I can switch it over.

Got dependency resolution issues with 5.3.0-rc1

The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[16.0.5,16.0.5]], but resolves to 16.4.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

The library com.google.firebase:firebase-analytics is being requested by various other libraries at [[16.0.6,16.0.6]], but resolves to 16.4.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

馃憢 hey - thanks for the report. v5.3.0 is now published on NPM which fixes this issue.

Please see the change log for more info & upgrade steps.

Not sure if it fixes it entirely.

I am trying to get a collection via reference, and same thing happens, no result.

getMenu() {
this.ref = firebase.firestore().collection('menu');
this.ref
.get()
.then(
querySnapshot => {
console.log('x');
}
).catch(
err => {
console.log('get menu error', err);
}
).finally(
err => {
console.log('get menu error', err);
}
).done(
err => {
console.log('get menu done', err);
}
);
}

@uditbansal2007 did you update the Android dependencies?

@LuisRodriguezLD Yup

I tried onSnapshot as well.. Not working..

this.ref = firebase.firestore().collection('user');

this.ref.onSnapshot(docSnapshot => {
console.log(Received doc snapshot:);
// ...
}, err => {
console.log(Encountered error:);
});

@uditbansal2007

This is working for me:

this.ref = firebase.firestore().collection('users');
this.ref.get()
    .then(querySnapshot => {
        console.log(querySnapshot);
    console.log(querySnapshot._docs);
})

I upgraded my build.gradle to 3.3.2, and it is now working for me. Thanks for the help @LuisRodriguezLD

Any update? I have the same environment, but it dont work :/

@yuritoledo this has been fixed in v5.3 Did you double check your build.gradle version?

yes, i've opened an issue #2270

This issue has returned again but in firestore js ,I have all other APIs of query and updating and creating document but GET it just returns an empty document without any error thrown ,Please help

@LuisRodriguezLD's solution worked for me.

this one:

this.ref = firebase.firestore().collection('users');
this.ref.get()
    .then(querySnapshot => {
        console.log(querySnapshot);
    console.log(querySnapshot._docs);
})

one issue is that the Google Firebase - Node.js docs say to get like this:

```
let getDoc = this.ref.get()
.then(doc => {
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data());
}
})
.catch(err => {
console.log('Error getting document', err);
});

`` i think this means simply that!doc.exists` is failing, not the queries. that documentation that might need updating. find it here: https://firebase.google.com/docs/firestore/query-data/get-data#get_a_document

Was this page helpful?
0 / 5 - 0 ratings