Create and update data
document creation or override
we provide docRef
setDoc(docRef, data)
docRef.set(data)
reference-less document creation
addDoc(collectionRef, data)
db.collection("message").add(data)
ref creation utility
doc(db, "users", userID, "HSK1", word.character)
doc(collectionRef, word.character)
collection(db, "players")
document partial update
updateDoc(docRef, data)
setDoc(docRef, data, { merge: true })
docRef.set(data, { merge: true })
docRef.update(data)
delete document document
docRef.delete()
deleteDoc(docRef)
mutate a single field
we use the update() function along with a directive on a specific field.
increment field
docRef.update({
count: FieldValue.increment(),
})
delete field
tsxdocRef.update({
fleet: FieldValue.delete(),
})
sever timestamp for field
this creates a trusted timestamp object. this is not needed when doing it from admin-sdk, because we may already trust a date created from the admin environment. Besides, it use firebase specific Timestamp instead of a multi platform iso date string.
docRef.update({
count: FieldValue.serverTimestamp(),
})
Increment
const partialUserDoc = {
activityScore: increment(1),
}