exports.updateRelatedCards = functions.firestore
.document('topic/{newTopic}')
.onWrite((snap, context) => {
const newTopic = snap.data();
// search for the recieved title in a 'relatedCards' subcollection
return firestore
.collection(`card/{anyCard}/relatedCards`)
.where('title', '==', newTopic.title)
.get()
.then(coll => {
const list = coll.docs.map(doc => doc.data());
return list ? list : 'nolist';
})
.then(list => console.log('list', list))
.catch(error => console.log('error', error));
});
是否可以.where()
在云函数中具有通配符的 Firestore 查询上使用?
尽管存在数据,但我一直得到一个空数组,我不明白我是在做什么,还是不可能。似乎没有提到对管理 Firestore 文档的查询https://firebase.google.com/docs/reference/admin/node/admin.firestore
您不能在任何上下文或任何 SDK 中使用通配符查询 Firestore。这是无效的:
firestore.collection(`card/{anyCard}/relatedCards`)
如果您要引用文档或集合,则需要提供它的真实路径。您不能通配路径的任何部分。
如果您尝试对已知集合和文档进行更简单的查询,它会工作得很好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句