To add sub collection to a document in Firestore with JavaScript, we call add or set.
For instance, we write
db.collection("users").doc(username).collection("booksList").doc(myBookId).set({
password,
name,
rollno,
});
to call set to update the entry in the 'booksList' collection with ID myBookId with the object we used as the argument for set.
And we write
db.collection("users").doc(username).collection("booksList").add({
password,
name,
rollno,
});
to call add to add the entry we call add with to the 'booksList' collection.