“Firestore Ajouter un document” Réponses codées

Firestore Ajouter un 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"
});
Delightful Donkey

Firestore définit un document

let data = {
  name: 'Los Angeles',
  state: 'CA',
  country: 'USA'
};

// Add a new document in collection "cities" with ID 'LA'
let setDoc = db.collection('cities').doc('LA').set(data);
Egg Salad

Ajout de 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);
});
Talented Thrush

Ajout de document à 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)
}
Tender Turtle

Réponses similaires à “Firestore Ajouter un document”

Questions similaires à “Firestore Ajouter un document”

Plus de réponses similaires à “Firestore Ajouter un document” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code