FieldValue.arrayRemove()基于属性值从对象数组中删除对象 [英] FieldValue.arrayRemove() to remove an object from array of objects based on property value

查看:69
本文介绍了FieldValue.arrayRemove()基于属性值从对象数组中删除对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下结构的文档:

I have a document with the following structure:

{
    "email" : "a@gmail.com",
    "value" : 100,
    "children" : [
                  {
                    "email" : "b@gmail.com",
                    "value" : 100
                  },
                  {
                    "email" : "b@gmail.com",
                    "value" : 200
                  }
                 ]
}

我想从 children 数组中删除电子邮件为 b@gmail.com 的所有元素.如果我像这样传递要删除的整个对象,则可以删除一项:

I want to remove all elements with the email b@gmail.com from the children array. I am able to remove one item if I pass the whole object to be removed like this:

FieldValue.arrayRemove(childObject)

但是我希望删除电子邮件为 b@gmail.com 的两个对象.无论如何,可以使用 FieldValue.arrayRemove()来实现这一点吗?

But I want both the objects with the email b@gmail.com to be removed. Is there anyway to achieve this using FieldValue.arrayRemove()?

推荐答案

arrayRemove 操作将从数组中删除您指定的确切项目.无法传递局部对象并删除所有与局部信息匹配的数组项.您必须输入要删除的每个完整项目.

The arrayRemove operation removes the exact item that you specify from the array. There is no way to pass a partial object and remove all array items that match the partial information. You will have to pass in each complete item that you want to remove.

如果您还不知道这些项目是什么,通常必须先阅读文档,将数组中的项目循环遍历以将其删除,然后将修改后的数组写回到文档中.

If you don't know what those items are yet, you will typically have to first read the document, loop over the items in the array to remove them, and write the modified array back to the document.

这篇关于FieldValue.arrayRemove()基于属性值从对象数组中删除对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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