Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Sub collections as nested object #1

Closed
raullarosa opened this issue Mar 5, 2018 · 3 comments
Closed

Sub collections as nested object #1

raullarosa opened this issue Mar 5, 2018 · 3 comments

Comments

@raullarosa
Copy link

In an attempt to migrate data from Firestore to the RealtimeDB I was hoping the collections of my data would be placed inside of an object. It seems trivial to accomplish and maybe I'm the only one with this use case so I will be working on this. (First PR coming through so bear with me!)

@raullarosa raullarosa changed the title Sub collections Sub collections as nested object Mar 5, 2018
@dalenguyen
Copy link
Owner

Hi @raullarosa. I'm not sure how many subcollections that you have, but there is a way to get subcollection if you have its name. You can put this line of code inside the query for the main collection to get the sub-collection. In this case, my sub-collection name is 'sub'.

db.collection(collectionName).doc(doc.id).collection('sub').get()
    .then(snapshot => {
      snapshot.forEach(doc => {
        console.log(doc.id, '=>', doc.data());
      })
})

This is a quick solution in case of you need it. I will come up with a better one later.

@talpanika6
Copy link

how can i export a sub collection in a nested object?
for example i have users collection, for export i will get all the users but without the sub collections of them.
i want to export users/{userId}/purchase for example, how can i achieve that?

dalenguyen pushed a commit that referenced this issue Apr 4, 2018
@dalenguyen
Copy link
Owner

Hi @talpanika6, I added the ability to export the sub-collection. You can check it now.

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

No branches or pull requests

3 participants