【问题标题】:How to add hashmap to hashmap that alredy exists without overriding the information?如何在不覆盖信息的情况下将 hashmap 添加到已经存在的 hashmap?
【发布时间】:2020-03-29 12:20:02
【问题描述】:

我想在 firsestore 中创建用户名列表(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);

【问题讨论】:

    标签: c# firebase google-cloud-firestore xamarin.android


    【解决方案1】:

    如果您想将 API 调用中的数据与文档中的现有数据合并,您有两种选择:

    1. 拨打UpdateAsync API

       documentReference.UpdateAsync(outmap);
      
    2. UpdateAsync 仅在文档​​已存在时才有效。如果不知道文档是否已经存在,可以call Set or SetAsync with SetOptions.MergeAll

       documentReference. SetAsync(outmap, SetOptions.MergeAll);
      

    【讨论】:

      猜你喜欢
      • 2011-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-06
      • 2010-09-27
      • 1970-01-01
      • 2018-08-29
      • 2014-10-14
      相关资源
      最近更新 更多