我正在尝试从Firestore删除文档,但没有收到错误消息,但是文档仍在数据库中:正因为如此,它一直存在于它所属的集合中。
云功能是:
exports.countdowns_crud = functions.https.onRequest((request, response) => {
var req = request;
var res = response;
if (request.method === 'DELETE') {
const countdownId = request.path.split('/')[1];
const deleteOperation = db.DeleteCountdown(countdownId);
if (!deleteOperation) {
console.log('Delete operation result: ', deleteOperation);
cors(req, res, () => {
res.status(204).send("DELETED");
});
}
else {
console.error(addOperation);
cors(req, res, () => {
res.status(500).send("INTERNAL SERVER ERROR");
});
};
return;
}
cors(req, res, () => {
res.status(405).send("NOT ALLOWED");
return;
});
})
DeleteCountdown函数在另一个模块中:
module.exports = {
DeleteCountdown: (countdownId) => {
const countdownsCollection = app.firestore.collection('countdowns');
countdownsCollection.doc(countdownId).delete()
.then((res) => {
console.log('Result: ', res);
return null;
})
.catch((e) => {
console.error(`unable to delete the countdown ${countdowmnId}: ${e}`);
return e;
});
}
}
这是Google Cloud函数中的逻辑,删除后我的react应用会正确调用它。传递的ID是正确的,不会返回任何错误,但文档会继续存在于集合中。
答案 0 :(得分:0)
我遇到了同样的问题,没有错误,并且返回了undefined
(工作时完全相同),因为我忘记设置要在Firebase控制台中编写的规则。