gpt4 book ai didi

typescript - Firestore 错误 : Update() requires either a single JavaScript object or an alternating list of field/value pairs

转载 作者:行者123 更新时间:2023-12-04 14:13:30 27 4
gpt4 key购买 nike

我正在尝试使用部署到 firebase 的函数将如下所示的新记录添加到 Firestore 文档。该功能是用 typescript 开发的:

功能:

admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
const app = express();

app.put('/v2/MYENDPOINT/add', async (req, res) => {
try
{
const res1 = db.collection('Bars2')
.doc('NHn8368LhIhNWHTOaEDo')
.update({
name: req.body['name'],
address: req.body['address1']
}).then(function() {
res.status(200).send(`Created a new Real bar2: ${(res1)}`)
})
.catch(function(error) {
res.status(400).send("Error writing document: " + error);
});


//res.status(200).send(`Created a new Real bar2: ${(res1)}`)
}
catch (error)
{
res.status(400).send(`Real bar2 not created!!! ${error}`)
}
})

我试着用 postman 来添加这个项目,但是代码触发了一个错误:

postman 新请求{ “名称”:“BAR C”, “地址”:“qwerty”

Real bar2 not created!!! Error: Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Value for argument "dataOrField" is not a valid Firestore value. Cannot use "undefined" as a Firestore value (found in field "address"). If you want to ignore undefined values, enable ignoreUndefinedProperties.

Firestore 结构在附图中。

知道我遗漏了什么吗?谢谢

enter image description here

[ How I Would Like the Data To Look On Right Side Of Image

最佳答案

错误信息的关键是:

Cannot use "undefined" as a Firestore value (found in field "address").

您的地址字段未定义,这不是 Firestore 文档的有效值。这意味着 req.body['address1'] 是未定义的。

也许您的意思是说“地址”而不是“地址 1”。

关于typescript - Firestore 错误 : Update() requires either a single JavaScript object or an alternating list of field/value pairs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62434737/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com