如何根据特定的键号删除数组元素? [英] How to remove an array element according to an especific key number?

查看:37
本文介绍了如何根据特定的键号删除数组元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在firebase中有以下文档:

I have the following document in firebase:

免责声明:香港专业教育学院试图检查arrayRemove(),但我只是无法工作背后的逻辑

disclaimer: ive tried checking arrayRemove() but i just cant get to work the logic behind it

Document
    ----- creaciones[]
               ------ 1{}
                  -------1
                  -------2
                  -------3
               ------ 2{}
                  -------1
                  -------2
                  -------3
               ------ 3{}
                  -------1
                  -------2
                  -------3

我想完全删除N个"creaciones"元素

I would like to delete the N "creaciones" element entirely

推荐答案

Cloud Firestore SDK无法提供按索引删除列表元素的方法.您需要做的是将文档读入内存,对内存中的数组进行更改,然后将该字段更新回Firestore.如果您担心多个客户端试图以此方式更改共享文档,则可以在事务中执行此操作.

Cloud Firestore SDKs don't offer a way to delete a list element by index. What you will have to do is read the document into memory, make the change to the array in memory, then update the field back to Firestore. You can do this in a transaction if you are concerned about multiple clients trying to change a shared document in this way.

这篇关于如何根据特定的键号删除数组元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆