【发布时间】:2021-08-19 14:55:32
【问题描述】:
我是 Firestore 的新手,我的问题是, 我正在使用 Visual Studio 和 JavaScript 来处理我的 Firestore 云功能。
我有两个集合,一个集合包含我发送或接收的最新消息,第二个集合包含您从特定用户发送和接收的所有文档。
我正在尝试使用云函数触发器,当您在设备上删除最新消息时,会调用一个云函数,该函数将删除该消息所引用的整个集合。
我已经能够使用 onDelete 函数,所以当最近的消息被删除时,该函数被调用,我可以得到被删除文档的所有详细信息,
然后我可以获得我想要删除的收藏的路径,我的问题是我不知道如何从此时删除所有文档。 我很确定我必须进行批量删除或类似的操作,但这对我来说很新,我已经在这里搜索过,我仍然很困惑任何帮助将不胜感激。
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp()
exports.onDeletfunctioncalled =
// recentMsg/currentuid/touid/{documentId}' This is the path to the document that is deleted
functions.firestore.document('recentMsg/currentuid/touid/{documentId}').onDelete(async(snap, context) => {
const documentIdToCollection = context.documentId
// this is the path to the collection I want deleted
return await
admin.firestore().collection(`messages/currentuid/${documentIdToCollection}`).get()
//what do i do from here ???
});
【问题讨论】:
标签: javascript google-cloud-firestore async-await google-cloud-functions