setDoc,add Doc for create documents - sana028/VueLearningsPoc GitHub Wiki

In cloud firestore database we can create documents inside collections using two methods 1.setDoc 2.addDoc

setDoc

1.setDoc is used to create a document with customized document name.

2.setDoc is useful to create a document when the document doesn't exist, if it exists it will act like update that mean rather than creating another duplicate it will update existed document data.

Syntax:

await setDoc(doc(db,'collection-name','document-name'),data)

addDoc

1.addDoc is used to create a documents with random names which are generated by firestore.

Syntax:

await addDoc(collection(db,'collection-name'),data)