Skip to content

MrD9877/firebase

Repository files navigation

SetUp

GET config from Settings--->Project Setting --->Add WEb app

FireBase

"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);

FireStore

Docs

https://firebase.google.com/docs/firestore

Write Data

setdata and addDoc works same except you need to give name of document and use doc for setData and collection for addDoc.

SetData

"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);
}

addData

"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);
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published