Firebase V9 Firestore Add Document Data Using addDoc() [2022]
4 min readJul 4, 2022
There are two methods that we can use to add document data to the Firebase Version 9 Cloud Firestore.
- addDoc() → you’re here
- setDoc()
Other Firebase 9 Tutorials in this series:
- Update Document Data Using setDoc()
- UPDATE Document Data Using updateDoc()
- DELETE Document Field Using updateDoc()
- DELETE Document Using deleteDoc()
- GET ALL DOCUMENTS Data From A Collection
- Get A Document By ID Using getDoc()
Note: Before going further, you’ll need to do three things:
- Create A Firebase Project from Firebase Console
- Register an app for Web (JavaScript)
- Add Firebase SDK to JavaScript Web app
In order to use the addDoc() method, we need to import three methods from the Firebase Firestore import statement.
- getDatabase() → Firestore database where we want to add data as a document.
- collection() → Where we want to add collection name and database references.
- addDoc() → Where we actually pass our data along with the collection name and db references.