【发布时间】:2018-03-27 14:04:56
【问题描述】:
很抱歉这个菜鸟问题,但我正要扔掉我的笔记本电脑。
我是 js 新手,一直在努力理解如何使用 Promise。
当一个对话被删除时,这个函数被触发并且应该循环抛出对话中包含的所有消息并删除它们。
我的问题是我不知道从哪里删除消息或如何删除。 如何删除消息?
exports.deleteMessages = functions.firestore
.document('users/{userId}/conversations/{conversationId}')
.onDelete(event => {
// Get an object representing the document prior to deletion
const deletedConversation = event.data.previous.data();
return database.collection('messages')
.where('conversationId', '==', deletedConversation.id).get()
.then(snapshot => {
snapshot.forEach(document => {
const data = document.data();
database.collection('messages').document(data.id).delete();
});
return console.log("Don't even no why I'm returning this")
})
.catch(error => {
console.log('Error when getting document ' + error)
});
});
【问题讨论】:
标签: javascript node.js firebase google-cloud-functions