Firebase V9 Firestore ADD DATA Using setDoc()

Raja Tamil
4 min readAug 1, 2022

There are two methods that we can use to add document data to the Firebase Version 9 Cloud Firestore.

Note: Before going further, you’ll need to do three things:

  1. Create A Firebase Project from Firebase Console
  2. Register an app for Web (JavaScript)
  3. 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";
  1. getDatabase() → Firestore database where we want to add data as a document.
  2. collection() → Where we want to add collection name and database references.
  3. setDoc() → Where we actually pass our data along with the collection name and db references.

--

--

Raja Tamil
Raja Tamil

Written by Raja Tamil

👇click the link and get 80% OFF on the premium web development courses (HTML5, CSS3, JavaScript ES6, Vue JS 3 & Firebase 10 https://softauthor.com