google-cloud-firestore - Firestore云函数监听子集合但不监听父集合

标签 google-cloud-firestore google-cloud-functions

这是从 Firebase 文档中复制的:- https://firebase.google.com/docs/firestore/extend-with-functions

评论说监听器将监听“用户”和所有子集合中的所有文档。

如何只监听子集合的所有文档而不监听父集合? (即,在此示例中,请勿收听“用户”中的文档。)

// Listen for changes in all documents in the 'users' collection and all subcollections
exports.useMultipleWildcards = functions.firestore
    .document('users/{userId}/{messageCollectionId}/{messageId}')
    .onWrite((change, context) => {
      // If we set `/users/marie/incoming_messages/134` to {body: "Hello"} then
      // context.params.userId == "marie";
      // context.params.messageCollectionId == "incoming_messages";
      // context.params.messageId == "134";
      // ... and ...
      // change.after.data() == {body: "Hello"}
    });index.js

最佳答案

根据文档Specify a group of documents using wildcards :

If you want to attach a trigger to a group of documents, such as any document in a certain collection, then use a {wildcard} in place of the document ID

另外,我在这里搜索了一个similar question :

A change to a subcollection organized under a document do not count as changes to the document itself. They will not trigger a snapshot event on that document.

Listening to a subcollection is not any different than listening to a top-level collection. In both cases, the listener will only be triggered by changes to documents within that collection or subcollection.

那么我可以得出结论,这是不可能的。

关于google-cloud-firestore - Firestore云函数监听子集合但不监听父集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64971603/

相关文章:

javascript - 使用nodejs从firestore文档中删除字段

java - 如何在 Firestore Android 中的事务中增加计数器?

google-cloud-platform - 使用 Artifact Registry 部署 Google Cloud Function 是否比使用 Container Registry 更快?

Firebase功能-您已超出部署配额

google-cloud-platform - gcloud 云函数部署失败代码 13 消息=执行环境失败"

javascript - 如何从 Firebase Cloud Function 在 Google Pub/Sub 中发布消息?

javascript - 为什么 firestore/AngularFire SDK 将多个 promise 打包到一个请求中?

ios - Flutter iOS 发布崩溃: Firebase FireStore Util

firebase - Firestore 可以扩展吗

google-cloud-platform - 当我尝试部署端点配置时,gcloud 抛出 PERMISSION_DENIED