Sometimes, we want to add Document with Custom ID to Firestore with JavaScript
In this article, we’ll look at how to add Document with Custom ID to Firestore with JavaScript.
How to add Document with Custom ID to Firestore with JavaScript?
To add Document with Custom ID to Firestore with JavaScript, we call the set method.
For instance, we write
db.collection("cities").doc("LA").set({
name: "Los Angeles",
state: "CA",
country: "USA",
});
to call set to add a document to the cities collection.
We call set with an object with the properties we want to add in a document.
We call doc with the ID of the document before we call set to populate its contents.
Conclusion
To add Document with Custom ID to Firestore with JavaScript, we call the set method.