【发布时间】:2018-06-04 20:28:58
【问题描述】:
我正在尝试编写一个函数,在文档中的数据(在 Firestore“艺术家”集合中)发生更改后,Google Cloud Functions 将在另一个集合(“显示”)中查找具有指向刚刚更改的文档(在“艺术家”集合中)的引用字段(“艺术家”)。
我似乎不知道如何查询参考字段。从使用艺术家文档的 ID 到路径,再到完整的 URL,我已经尝试了所有方法。但我在 Google Cloud Function 控制台中遇到错误:
Error getting documents Error: Cannot encode type ([object Undefined]) to a Firestore Value
这是我的代码示例:
exports.updateReferenceArtistFields = functions.firestore
.document('artists/{artistId}').onWrite(event => {
var artistRef = event.data.data();
var artistId = artistRef.id;
var ShowsRef = firestore.collection('shows');
var query = ShowsRef.where('artist', '==', artistId).get()
.then(snapshot => {
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
});
})
.catch(err => {
console.log('Error getting documents', err);
});
});
【问题讨论】:
标签: javascript firebase google-cloud-functions google-cloud-firestore