更新firestore文档中嵌套对象中的字段? [英] Update fields in nested objects in firestore documents?
问题描述
我的数据结构如下:
我想在第一个对象中编辑test键的值。我按照
test2键消失了。但是,我只想更新test的值并保留test2。
这个问题的解决方案是什么?
根据链接你提供的,它说:
如果您的文档包含嵌套对象,您可以使用点符号来引用文档中的嵌套字段当你调用update()时:
因此你需要使用点符号
能够只更新一个字段而不覆盖,所以这样:
var setAda = dbFirestore.collection('users') .doc('alovelace')。update({
first.test:12345
});
那么你将拥有:
首先
测试:12345
test2:abcd
I have a data structure like:
I want to edit the value of "test" key in "first" object. I followed the document on https://firebase.google.com/docs/firestore/manage-data/add-data
But it did not work for me.
The nodejs code:
var setAda = dbFirestore.collection('users').doc('alovelace').update({
first : {
test: "12345"
}
});
The result in firestore:
The "test2" key was gone. However, I only want to update the value of "test" and keep the "test2".
Any solution for this problem?
According to the link you provided, it says this:
If your document contains nested objects, you can use "dot notation" to reference nested fields within the document when you call update():
Therefore you need to use dot notation
to be able to update only one field without overwriting, so like this:
var setAda = dbFirestore.collection('users').doc('alovelace').update({
"first.test": "12345"
});
then you will have:
first
test: "12345"
test2: "abcd"
这篇关于更新firestore文档中嵌套对象中的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!