Firebase V9 Firestore ADD DATA Using setDoc()
4 min readAug 1, 2022
There are two methods that we can use to add document data to the Firebase Version 9 Cloud Firestore.
- addDoc()
- setDoc() → you’re here
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
Using the setDoc() method, you can add a document to the Firestore database by creating:
Add Data Using setDoc() With Auto-ID
In order to use the setDoc() method, we need to import three methods from the Firebase Firestore Import Statement.
import { getFirestore, collection, setDoc } from "firebase/firestore";
- getDatabase() → Firestore database where we want to add data as a document.
- collection() → Where we want to add collection name and database references.
- setDoc() → Where we actually pass our data along with the collection name and db references.