firestore set id or auto generate code example

Example: firestore create document with auto id

// Add a new document with a generated id.
db.collection("cities").add({
    name: "Tokyo",
    country: "Japan"
})
.then(function(docRef) {
    console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
    console.error("Error adding document: ", error);
});
---------------------------
//If you want to specify id then use .set() 
// e.x   \/
db.collection("cities").doc("TYO").set({
    name: "Tokyo",
    country: "Japan"
})

Tags:

C Example