Hola quiero que al crear un nuevo documento, donde dice "projectId" se pase al campo "projectId" el id del documento que se genera automáticamente, ¿es esto posible?
Este es mi código:
addDoc(collection(db, "projects"), { name: project, uid: currentUser, projectId: 'here the proyectId that i dont know how to pass it' })Estoy usando Firebase v9 Modular, Firestore y React JS
Lo siguiente hará el truco:
import { collection, doc, setDoc } from "firebase/firestore"; // Add a new document with a generated id const newDocRef = doc(collection(db, "projects")); // Set the doc, using the id property of the DocumentReference await setDoc(newDocRef, { name: project, uid: currentUser, projectId: newDocRef.id } );