[英]Firestore - Adding a new field sets it as "map"
I'm trying to add a new field inside my document.我正在尝试在我的文档中添加一个新字段。
When I'm setting it, it sets the field as string (what I need)当我设置它时,它将字段设置为字符串(我需要的)
But when I'm trying to add something new (update)
, it sets it as map
但是当我试图添加一些新的东西
(update)
时,它将它设置为map
Code:代码:
await firestore().collection(groupID).doc('images').collection(licenseNumber).doc('images')
.get()
.then((docSnapshot) => {
if (docSnapshot.exists) {
getImages();
firestore().collection(groupID).doc('images').collection(licenseNumber).doc('images')
.update({
// [length]: reference.child(response.assets[0].fileName).fullPath,
[response.assets[0].fileName.toString()]: reference.child(response.assets[0].fileName).fullPath,
})
.then(() => {
setIsLoading(false);
})
} else {
getImages();
firestore().collection(groupID).doc('images').collection(licenseNumber).doc('images')
.set({
// [length]: reference.child(response.assets[0].fileName).fullPath,
[response.assets[0].fileName.toString()]: reference.child(response.assets[0].fileName).fullPath,
})
.then(() => {
setIsLoading(false);
})
}
})
I don't know where is the problem.我不知道问题出在哪里。 Maybe It's a stupid mistake or typo.
也许这是一个愚蠢的错误或错字。
That is expected behavior: when you have a .
这是预期的行为:当你有一个
.
in the field name when updating a document, that dot is interpreted as indicated a path to a subfield.在更新文档时的字段名称中,该点被解释为指示子字段的路径。 Such a mapping is not done when you call
set
.当您调用
set
时,不会完成这样的映射。
So one option is to call set
with merge: true
to get the updating behavior in an operation that doesn't parse the .
因此,一种选择是使用
merge: true
调用set
以在不解析.
. .
Alternatively you can construct a FieldPath
object and pass that to update
, in which case the .
或者,您可以构造一个
FieldPath
object 并将其传递给update
,在这种情况下.
will (should?) be ignored there too.将(应该?)在那里也被忽略。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.