“Firestore Agregar documento” Código de respuesta

Firestore Agregar documento

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 establece un documento

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

Agregando 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

Agregar documento a 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

Respuestas similares a “Firestore Agregar documento”

Preguntas similares a “Firestore Agregar documento”

Más respuestas relacionadas con “Firestore Agregar documento” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código