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);
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);
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"
})
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'
});
firebase update data
await firebase.database().ref().update(updates);
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")
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us