代码之家  ›  专栏  ›  技术社区  ›  Agung

在子集合文档上触发onCreate cloud函数后,如何从主集合访问文档?

  •  0
  • Agung  · 技术社区  · 7 年前

    假设我收集了这样的照片:

    enter image description here

    enter image description here

    我想扣动扳机,如果新的 likers 文档已创建,则我要增加 point 主收款单中的字段+=1( q27yiVv4g7XVgiaG7c7a ). 如何获取这些信息

    应该使用下面的代码,但我不知道如何访问该文档

    exports.createUser = functions.firestore
        .document('photos/{photoId}/likers/{likersId}')
        .onCreate((snap, context) => {
    
    
        });
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Doug Stevenson    7 年前

    可以使用通配符构建对文档的引用 photoId

    const photoId = context.params.photoId
    const photoRef = snap.ref.firestore.collection('photos').doc(photoId)