c# - 如何在不覆盖信息的情况下将哈希图添加到已经存在的哈希图中?
问题描述
我想在第一存储区中列出用户名列表(hashmap 中的 hashmap)。
我不想每次运行操作时都遍历参与者中的数据。
HashMap innermap = new HashMap();
HashMap outmap= new HashMap();
DocumentReference documentReference =Signup2.Getdatabase(Context).Collection("teams").Document(userdata.GetString("teamcode", "0000"))
.Collection("workout").Document(position.GetString("workoutdateposition", ""));
innermap.Put("username", userdata.GetString("username", ""));
outmap.Put("participants", innermap);
documentReference.Set(outmap);
解决方案
如果要将 API 调用中的数据与文档中的现有数据合并,有两种选择:
-
documentReference.UpdateAsync(outmap);
UpdateAsync
只有当文档已经存在时才有效。如果您不知道文档是否已经存在,您可以调用Set
orSetAsync
withSetOptions.MergeAll
:documentReference. SetAsync(outmap, SetOptions.MergeAll);
推荐阅读
- java - 我需要创建一个发送电子邮件的函数,为什么当我在我的 main 中调用它以确认它是否已发送时它显示 null?
- python - 关于 numpy 数组的操作
- java - 新建一个主键相同的java对象,Hibernate merge() 生成更新sql而不是重复主键
- java - 如何计算来自 Java 中“流”的传入消息?
- razor - 为 ASP.NET Core MVC 中 HttpGet 的输入框赋值
- pine-script - 我想计算特定时间段内收盘价减去开盘价大于20的天数
- powershell - Powershell + XAML + 搜索框 + 捕获和显示
- java - 如何检查嵌入式 ActiveMQ Spring Boot 上的待处理队列消息?
- kubernetes - k8s 命令健康探测的最佳实践
- r - R中的checkboxInput闪亮