GET config from Settings--->Project Setting --->Add WEb app
"use client";
import { initializeApp } from "firebase/app";
// import { getAnalytics } from "firebase/analytics";
const firebaseConfig = {
apiKey: "AIzaSyB-o3rBF_cOs_y8l39J8t4XkAVTPJrUoGQ",
authDomain: "test-871c8.firebaseapp.com",
projectId: "test-871c8",
storageBucket: "test-871c8.firebasestorage.app",
messagingSenderId: "56089331460",
appId: "1:56089331460:web:7f35ed4cd5590839637251",
measurementId: "G-8DB4N0E948",
};
export const app = initializeApp(firebaseConfig);
// export const analytics = getAnalytics(app);Docs
https://firebase.google.com/docs/firestore
setdata and addDoc works same except you need to give name of document and use doc for setData and collection for addDoc.
"use client";
import { doc, setDoc, getFirestore } from "firebase/firestore";
import { app } from "./firebase";
const db = getFirestore(app);
export async function addData() {
const setDocres = await setDoc(doc(db, "collection", "doc"), {
name: "Los Angeles",
state: "CA",
country: "USA",
});
console.log(setDocres);
}"use client";
import { getFirestore, addDoc, collection } from "firebase/firestore";
import { app } from "./firebase";
const db = getFirestore(app);
export async function addData() {
///randoem string is assigned as doc name
const res = await addDoc(collection(db, "cities"), {
name: "Los Angeles",
state: "CA",
country: "USA",
});
console.log(res);
}