Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Firestore nested collections #559

Closed
ITServicesAM opened this issue Dec 4, 2017 · 5 comments
Closed

Firestore nested collections #559

ITServicesAM opened this issue Dec 4, 2017 · 5 comments

Comments

@ITServicesAM
Copy link

ITServicesAM commented Dec 4, 2017

hello eddy,

first of all thx for this amazing plugin!

I am trying to use the new firestore feature. The firebase docs are saying that yon can nest a collection under a document ref. Using your plugin the nesting doesn´t work. The collection is always being created under the root of the database.

Here my example code

let userDoc = firestore.collection('users').doc(user.uid);
userDoc.set({email: user.email});
userDoc.collection('worktimes').doc(data.key).set({
    date: data.value.date,
    reverseOrderDate: data.value.reverseOrderDate,
    workTimeEnd: data.value.workTimeEnd,
    workTimeStart: data.value.workTimeStart,
    workingMinutesBrutto: data.value.workingMinutesBrutto,
    workingMinutesNetto: data.value.workingMinutesNetto,
    workingMinutesOverTime: data.value.workingMinutesOverTime,
    workingMinutesPause: data.value.workingMinutesPause
});

I´m expecting the worktimes data under the user document but in the firebase console there is a collection "worktimes" at the root level.

The data comes from an api call. Any ideas?
Thx Armin

@ITServicesAM
Copy link
Author

no one?

@ITServicesAM
Copy link
Author

Accidentally closed

@ITServicesAM ITServicesAM reopened this Dec 6, 2017
@EddyVerbruggen
Copy link
Owner

Looks like a bug, thanks for reporting it!

@ITServicesAM
Copy link
Author

I think I found the problem, in firebase.android.ts you are creating a collection from the root db instance everytime. If I don´t chain the collection.doc.collection calls instead get the collection with a deeplink (users/${user.uid}/worktimes) it works.

We need to find a way to determan if the collection is a chained one or the root one. If chained generate the path relative to the document otherwise generate the path from the root db.

@EddyVerbruggen
Copy link
Owner

Found a way to make it behave properly! With 5.0.3 you will be able to do for instance:

    const streetsCollectionRef: firestore.DocumentReference = firebase.firestore()
            .collection("cities")
            .doc("SF")
            .collection("streets");

or even deeper:

    const docRef: firestore.DocumentReference = firebase.firestore()
            .collection("cities")
            .doc("SF")
            .collection("streets")
            .doc("QZNrg22tkN8W71YC3qCb"); // id of some doc in the 'streets' collection

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants