Always have an entityId available in the pre-save callback instead of being undefined when creating a doc. #351
Nicholas-Fisher
started this conversation in
Ideas
Replies: 1 comment
-
Hi @Nicholas-Fisher |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So right now the entityId passed into the pre-save call back is "string Id of the entity or undefined if new".
Rather than it being undefined, would it be possible to pre-generate the document ID that will be used when saving the document so that we always have this available in the carious callback functions? Even on document creation?
Firebase lets you peak at the ID that it'll use to save the document when you create a Document object using addDoc. Here's an example from https://firebase.google.com/docs/firestore/manage-data/add-data:
import { collection, addDoc } from "firebase/firestore";
// Add a new document with a generated id.
const docRef = await addDoc(collection(db, "cities"), {
name: "Tokyo",
country: "Japan"
});
console.log("Document written with ID: ", docRef.id);
docRef.id can be surfaced as the entityId even before a document is saved to firestore. This would be great to have in the callbacks!
Beta Was this translation helpful? Give feedback.
All reactions