如何仅更新数组中的单个值 [英] How to update only a single value in an array

查看:46
本文介绍了如何仅更新数组中的单个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  const docRef = firestore.collection("SequenceId").doc(doc.id);docRef.update({序列号: {[x]:假}}) 

当前我的数据库是

执行上述代码后,我的数据库

但是我只想将2:的值更新为false,同时保持3:和4:.这里3:和4:被删除.

解决方案

Firestore当前不提供更新索引数组中单个项目的功能.您的替代方法是从文档中读取整个数组,在内存中对其进行修改,然后将整个数组写回到文档中.

唯一可用的数组更新操作是添加一个新数组("arrayUnion")并从数组中删除一项("arrayRemove").您可以阅读这些操作的文档./p>

 const docRef = firestore.collection("SequenceId").doc(doc.id);

 docRef.update({

                sequencenumber: {
                    [x]: false 
                  }

             })

Currently my database is

After the above code is executed my database

But i want only the value of 2: to be updated to false, while maintaining 3: and 4: . Here 3: and 4: gets deleted.

解决方案

Firestore doesn't currently offer the ability to update a single item in an indexed array. Your alternative is to read the entire array from the document, modify it in memory, then write the entire array back to the document.

The only array update operations available are adding a new array ("arrayUnion") and removing an item from an array ("arrayRemove"). You can read the documentation for those operations.

这篇关于如何仅更新数组中的单个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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