firebase将数据添加到数组中

发布于 2025-02-12 08:31:58 字数 393 浏览 0 评论 0 原文

我想在无删除现有产品的情况下将新产品添加到Allproducts阵列中。

这是数据库。

和代码。该解决方案始终覆盖现有产品。

I would like to add a new product to the allProducts array without deleting the existing product.

Here is the database.
enter image description here

And the code. This solution always overwrite the existing product.
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红墙和绿瓦 2025-02-19 08:31:58

如果要将项目添加到现有数组中,则可以:

您可能想在这里做后者。

If you want to add an item to an existing array, you can:

  • Either load the document, get the existing array from that, add the item to it, and then write the entire array back to the database.
  • Or you can use the array-union operator that is described in the documentation on updating an item in an array.

You'll probably want to do the latter here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文