我正在尝试使用部署到 firebase 的函数将如下所示的新记录添加到 Firestore 文档中。该功能是用打字稿开发的:
功能:
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}`)
}
})
Run Code Online (Sandbox Code Playgroud)
我尝试使用邮递员添加此项目,但代码触发了错误:
邮递员新请求 { "name": "BAR C", "address": "qwerty" }
真正的 bar2 没有创建!错误:Update() …