Nativescript-plugin-firebase: Firestore nested collections

Created on 4 Dec 2017  路  5Comments  路  Source: EddyVerbruggen/nativescript-plugin-firebase

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

Android bug iOS

All 5 comments

no one?

Accidentally closed

Looks like a bug, thanks for reporting it!

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.

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
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bunower picture bunower  路  3Comments

phatakrajan picture phatakrajan  路  4Comments

dopefatimah picture dopefatimah  路  3Comments

EddyVerbruggen picture EddyVerbruggen  路  3Comments

b02505048 picture b02505048  路  3Comments