Firebase 侦听firestore中的多个节点。。。?

Firebase 侦听firestore中的多个节点。。。?,firebase,google-cloud-functions,google-cloud-firestore,Firebase,Google Cloud Functions,Google Cloud Firestore,在我的例子中,我有一个集合“companys”,其中有50个不同的公司,每个公司都有一个集合“addedshift”-在我的node.js中,我想设置一个侦听器,侦听这些公司的“addedshift”,这是可能的,还是我必须为此进行演练 我想要这样的东西: firestore.document("companies/{*}/addedShifts").onWrite()=> 其中{*}将是公司ID的“通配符”中的第二个示例似乎表明它是可能的: 您在使其工作时遇到问题了吗?我在下面为Nod

在我的例子中,我有一个集合“companys”,其中有50个不同的公司,每个公司都有一个集合“addedshift”-在我的node.js中,我想设置一个侦听器,侦听这些公司的“addedshift”,这是可能的,还是我必须为此进行演练

我想要这样的东西:

firestore.document("companies/{*}/addedShifts").onWrite()=>

其中{*}将是公司ID的“通配符”

中的第二个示例似乎表明它是可能的:


您在使其工作时遇到问题了吗?

我在下面为Node.js编写了一个答案,但直到现在才看到您使用云函数进行了标记。您希望在常规Node.js客户端或云功能中实现这一点吗?因为两者的答案可能有很大不同。@FrankvanPuffelen很抱歉,对于云函数(will delet node.js tag)-您所指的答案是否仍然与我的案例相关?更新了我的答案。太好了,文档中遗漏了该部分-将进行研究,ty:)(y)
// Listen for changes in all documents and all subcollections
exports.useMultipleWildcards = functions.firestore
    .document('users/{userId}/{messageCollectionId}/{messageId}')
    .onWrite((event) => {
        // If we set `/users/marie/incoming_messages/134` to {body: "Hello"} then
        // event.params.userId == "malcolm";
        // event.params.messageCollectionId == "incoming_messages";
        // event.params.messageId == "134";
        // ... and ...
        // event.data.data() == {body: "Hello"}
    });