Answers for "firebase update document"

5

firestore set a document

let data = {
  name: 'Los Angeles',
  state: 'CA',
  country: 'USA'
};

// Add a new document in collection "cities" with ID 'LA'
let setDoc = db.collection('cities').doc('LA').set(data);
Posted by: Guest on June-05-2020
1

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"
})
Posted by: Guest on January-16-2021
0

firestore update map

let initialData = {
  name: 'Frank',
  age: 12,
  favorites: {
    food: 'Pizza',
    color: 'Blue',
    subject: 'recess'
  }
};

let updateNested = db.collection('users').doc('Frank').update({
  age: 13,
  'favorites.color': 'Red'
});
Posted by: Guest on June-05-2020
0

firebase update data

await firebase.database().ref().update(updates);
Posted by: Guest on October-09-2020
0

document.set() firebasefirestore java

var washingtonRef = db.collection("cities").doc("DC");
// Atomically add a new region to the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
});
// Atomically remove a region from the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayRemove("east_coast")
});
Posted by: Guest on July-20-2020

Code answers related to "firebase update document"

Browse Popular Code Answers by Language