【发布时间】:2022-12-01 22:37:28
【问题描述】:
I want to remove the type 'A' from the capital. How do I do it? Any code example will be appreciated. I am working on a react project.
【问题讨论】:
标签: reactjs firebase google-cloud-firestore
I want to remove the type 'A' from the capital. How do I do it? Any code example will be appreciated. I am working on a react project.
【问题讨论】:
标签: reactjs firebase google-cloud-firestore
As far as I can tell there is nonestedarray in the document you shared. In that case you can use the arrayRemove operator to remove a unique item from the array:
const cityRef = doc(db, "cities", "capital");
await updateDoc(cityRef, {
region: arrayRemove({ type: "A" })
});
A few things to note here:
arrayRemove operator, as it only removes array items that exactly and completely match the value you pass.arrayRemove operations removes all items that match. So if you have multiple { type: "A" } items in the array, all will be removed.If your use-case can't satisfy any of the requirements above, the way to remove the item would be to:
【讨论】: