firestore create document with auto id code example
Example 1: firestore set a document
let data = {
name: 'Los Angeles',
state: 'CA',
country: 'USA'
};
let setDoc = db.collection('cities').doc('LA').set(data);
Example 2: firestore create document with auto 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);
});
---------------------------
db.collection("cities").doc("TYO").set({
name: "Tokyo",
country: "Japan"
})
Example 3: firebase cloud method update
firebase deploy --only functions:functionNameHere
Example 4: document.set() firebasefirestore java