EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 444 forks source link

Observable on collection(someCol).doc(someDoc).collection(someSubCol) does not return any data #1564

Closed Slanfan closed 4 years ago

Slanfan commented 4 years ago

I have problems getting my observable on subcollection to work. If I add the observable on the first doc level I have no issues returning data but when I reference to a subcollection of a specific document I cannot get the observable to return any document from within the subcollection.

Please help!

this.attendees$ = Observable.create(subscriber => {
            const colRef: firestore.CollectionReference = firebase.firestore.collection("events").doc(this.eventDocId).collection("players");
            colRef
                .orderBy("name", "asc")
                .onSnapshot((snapshot: firestore.QuerySnapshot) => {
                    console.log("... fetching attendees, found " + snapshot.docs.length + " attendees");
                    this.zone.run(() => {
                        this.attendees = [];
                        snapshot.forEach(docSnap => {
                            console.log("Data (" + docSnap.id + ")", docSnap.data());
                            const playerData = <EventPlayer>docSnap.data();
                            playerData.docId = docSnap.id;
                            this.attendees.push(playerData);
                        });
                        subscriber.next(this.attendees);
                    });
                });
        });
manojdcoder commented 4 years ago

Are you saying the onSnapshot method is never called Or it's just your subscribers are not notified?

Slanfan commented 4 years ago

Are you saying the onSnapshot method is never called Or it's just your subscribers are not notified?

console message within onSnapshot never reach my console so I guess the onSnapshot method never gets called.

Slanfan commented 4 years ago

@manojdcoder did you have a suggestion to solve this? Or maybe @EddyVerbruggen have a solution.

It might be I do something wrong as I’m a n00b but I have the same code running on two other collections (not subCollections though) in the app and that works.

manojdcoder commented 4 years ago

@Slanfan I ran some tests on my end with exact same data model you have showcased, the snapshot method is always called (upon creating / updating / deleting players).

If you still have issues, please share a sample project where the issue can be reproduced.

Slanfan commented 4 years ago

Did run it on my iOS device instead of the Android Emulator and all worked fine. Need to test and clean the emulator and reinstall there. Will re-open if more help is needed. Thanks anyways.