How to add Document with Custom ID to firestore

Harvey Dent picture Harvey Dent · Jan 31, 2018 · Viewed 67.8k times · Source

Is there any chance to add a document to firestore collection with custom generated id, not the id generated by firestore engine?

Answer

Finlay Percy picture Finlay Percy · Jan 31, 2018

To use a custom ID you need to use .set, rather than .add

This creates a document with the ID "LA":

db.collection("cities").doc("LA").set({
    name: "Los Angeles",
    state: "CA",
    country: "USA"
})

This is taken from the official docs here