invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.66k stars 2.21k forks source link

firestore get API not working #2037

Closed uditbansal2007 closed 5 years ago

uditbansal2007 commented 5 years ago

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:

# 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


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

LuisRodriguezLD commented 5 years ago

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

uditbansal2007 commented 5 years ago

Workaround: https://stackoverflow.com/questions/55476263/unable-to-fetch-data-from-firebase-firestore-in-react-native

mikehardy commented 5 years ago

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

Salakar commented 5 years ago

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.

mikehardy commented 5 years ago

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

Salakar commented 5 years ago

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)

uditbansal2007 commented 5 years ago

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.

Salakar commented 5 years ago

👋 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.

uditbansal2007 commented 5 years ago

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

LuisRodriguezLD commented 5 years ago

@uditbansal2007 did you update the Android dependencies?

uditbansal2007 commented 5 years ago

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

LuisRodriguezLD commented 5 years ago

@uditbansal2007

This is working for me:

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

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

yuritoledo commented 5 years ago

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

LuisRodriguezLD commented 5 years ago

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

yuritoledo commented 5 years ago

yes, i've opened an issue #2270

Robotecom commented 5 years ago

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

masterkrang commented 5 years ago

@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