[英]Write data in to nested object in firebase firestore
I have a data structure that looks as follows:我有一个如下所示的数据结构:
This is the top level of the collection:这是集合的顶层:
I want to write to increment the field count but I can't do it.我想写来增加字段数,但我做不到。 I've tried so many different methods that I'd rather not go through all of them.
我已经尝试了很多不同的方法,我不想 go 通过所有这些方法。 The closest I've gotten was through:
我最接近的是通过:
const pageRef = admin.firestore().collection("pages").doc(image.page);
pageRef.set(
{
[`images.${image.position}.count`]: admin.firestore.FieldValue.increment(
1
),
},
{ merge: true }
);
But that leaves me with:但这给我留下了:
Please help.请帮忙。 Changing the structure of pages is an option.
更改页面结构是一种选择。
This is what I've tried to replicate: Update fields in nested objects in firestore documents?这就是我试图复制的内容: Update fields in nested objects in firestore documents?
The issue is on how the point notaition is being used.问题在于如何使用点符号。
In the Post you shared the example they use is:在您分享的帖子中,他们使用的示例是:
var setAda = dbFirestore.collection('users').doc('alovelace').update({ "first.test": "12345" });
Applying this to your Code and model would be:将此应用于您的代码和 model 将是:
const pageRef = admin.firestore().collection("pages").doc(image.page);
pageRef.set(
{
`images[${image.position}].count`: admin.firestore.FieldValue.increment(
1
),
},
{ merge: true }
);
This will affect the element in the Array Images, the element image.position
its value count.这将影响 Array Images 中的元素,元素
image.position
其值计数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.