how to add sub collection to a document in firestore?

Javascriptnode.jsFirebasevue.jsGoogle Cloud-Firestore

Javascript Problem Overview


there is no documentation about how add sub collection in a document in firestore, how to add a sub collection by using a web app? even tried like this but didn't worked. how can i add a sub collection in apps by using code? is there any way to do it or it will be better to use firebase real time database? if it so, please let me know how to do it in firebase as welli want to add like this i did this but iam getting an error like this the error says this

Javascript Solutions


Solution 1 - Javascript

Your code should work if you change .set to .add. Cloud Firestore will then issue a new ID for that document. If you want to specify the document ID, then you'll need to do this...

Set a book with a given ID

db.collection('users').doc(this.username).collection('booksList').doc(myBookId).set({
  password: this.password,
  name: this.name,
  rollno: this.rollno
})

This page details how to Add data to Cloud Firestore

Add a book

db.collection('users').doc(this.username).collection('booksList').add({
  password: this.password,
  name: this.name,
  rollno: this.rollno
})

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser8167002View Question on Stackoverflow
Solution 1 - JavascriptJason BerrymanView Answer on Stackoverflow