Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

firestore add document

import { doc, setDoc } from "firebase/firestore"; 

// Add a new document in collection "cities"
await setDoc(doc(db, "cities", "LA"), {
  name: "Los Angeles",
  state: "CA",
  country: "USA"
});
Comment

adding document to firebase firestore

Adding new document with auto generated id
//imports
import { db } from "../../config/firebase.config";
import { collection, addDoc } from "firebase/firestore";

//code inside component
const addData = async () => {
	collectionRef = collection(db, "collectionName")
    payload = { whatever your payload is }
    await addDoc(collectionRef, payload)
}
Comment

Adding in firestore

// Add a new document in collection "cities"
db.collection("cities").doc("LA").set({
    name: "Los Angeles",
    state: "CA",
    country: "USA"
})
.then(() => {
    console.log("Document successfully written!");
})
.catch((error) => {
    console.error("Error writing document: ", error);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery ajax responsetext 
Javascript :: how to double array data in js 
Javascript :: javascript does not equal 
Javascript :: check checkbox based on value using jquery 
Javascript :: javascript array to table 
Javascript :: vowel array 
Javascript :: check if url is http or https javascript 
Javascript :: date time js 
Javascript :: Removing Service Workers Programmatically 
Javascript :: Reached heap limit Allocation failed - JavaScript heap out of memory nodejs 
Javascript :: route pass props to component 
Javascript :: vue 3 computed 
Javascript :: javascript format number 2 digits 
Javascript :: how to change size of image js 
Javascript :: trigger input javascript 
Javascript :: js audio stream player 
Javascript :: Nodemailer gmail new configuration 
Javascript :: get object key name in js 
Javascript :: using bootstrap in react 
Javascript :: difference between statement and expression 
Javascript :: loop over string js 
Javascript :: set package json to install latest version 
Javascript :: get date in javascript 
Javascript :: discord js mention 
Javascript :: how to get url params value in node js 
Javascript :: remove item from array in jquery 
Javascript :: Count of positives / sum of negatives 
Javascript :: Check if user logged in Wordpress through JS 
Javascript :: javascript check if element is visible on screen 
Javascript :: turn Iterator into array JS 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =