Firestore - 如何从 Android 更新其键中包含句点(.)的字段? [英] Firestore - How to update a field that contains period(.) in it's key from Android?

查看:13
本文介绍了Firestore - 如何从 Android 更新其键中包含句点(.)的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新包含句点 (.) 的字段未按预期工作.在文档中,可以通过提供点分隔的字段路径字符串或提供 FieldPath 对象来更新嵌套字段.因此,如果我有一个字段并且它的键是 "com.example.android" 我如何更新这个字段(来自 Android)?

Updating a field contains period (.) is not working as expected. In docs, nested fields can be updated by providing dot-seperated filed path strings or by providing FieldPath objects. So if I have a field and it's key is "com.example.android" how I can update this field (from Android)?

在我的场景中,如果文档不存在,我必须设置它,否则更新文档.因此,第一组是创建包含句点的字段,然后尝试更新相同的字段,因为它包含句点,因此使用嵌套字段创建新字段.

In my scenario I've to set the document if it's not exists otherwise update the document. So first set is creating filed contains periods like above and then trying update same field it's creating new field with nested fields because it contains periods.

db.collection(id).document(uid).update(pkg, score)

推荐答案

你想做的是可能的:

FieldPath field = FieldPath.of("com.example.android");
db.collection(collection).document(id).update(field, value);

这篇关于Firestore - 如何从 Android 更新其键中包含句点(.)的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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