我在阿尔及利亚有以下记录
enterprise_name:"manaslu enterprise",
objectID:"14417261",_quotation:[{shamagri_title:"paper ad",price:4000,
unit:"per sq inc",
description:"5*5",
geo_latitude:40,
geo_longitude:89,
type:"service"}
]
我想在报价集合更新时将以下对象添加到报价数组中。
const enter = db.collection("quotation").doc("14417261");
return enter.update({
shamagri_title: "banner ad",
rate: 4000,
unit: "per sq inch",
description: "15 * 10",
type: "service",
});
我尝试使用云功能中的以下代码来更新algolia记录
functions.firestore
.document("quotation/{quotationId}")
.onUpdate((change) => {
const newData = change.after.data();
const objectID = change.after.id;
return index.partialUpdateObjects({
_quotation: {
_operation: "Add",
value: newData,
},
objectID,
});
});
基于firebase云功能,它确实基于更新提供了objectId 我已经根据来自algolia的以下示例使用了上面的partialUpdateObjects函数
index.partialUpdateObject({
_tags: {
_operation: 'AddUnique',
value: 'public',
},
objectID: 'myID',
})
.then(({ objectIDs }) => {
console.log(objectIDs);
});
但是,在我甚至没有部署云功能之前,我都会收到以下错误消息
Argument of type '{ _quotation: { _operation: string; value: FirebaseFirestore.DocumentData; }; objectID: string; }' is not assignable to
parameter of type 'readonly Record<string, any>[]'.
Object literal may only specify known properties, and '_quotation' does not exist in type 'readonly Record<string, any>[]'.
19 _quotation: {
~~~~~~~~~~~~~
20 _operation: "Add",
~~~~~~~~~~~~~~~~~~~~~~~~~~
21 value: newData,
~~~~~~~~~~~~~~~~~~~~~~~
22 },
~~~~~~~
这里可能出了什么问题?
答案 0 :(得分:1)
我通过使用摆脱了错误
partialUpdateObject
代替了partialUpdateObjects
,后者用于更新多个记录。在Algolia中,对象和对象对于单数和复数记录更新都具有巨大的区别