我可以在云功能中以通配符作为管理员查询firestore吗? [英] Can I query firestore with a wildcard as admin in a cloud function?

查看:44
本文介绍了我可以在云功能中以通配符作为管理员查询firestore吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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));
  });

是否可以在云功能中具有通配符的Firestore查询上使用 .where()?

is it possible to use .where() on a firestore query that has a wildcard in a cloud function?

尽管有数据,但我不断得到一个空数组,我不知道自己是否正在做绞拧或是否做不到.似乎没有提及在管理员firestore文档上进行查询https://firebase.google.com/docs/reference/admin/node/admin.firestore

Despite the data existing, I keep getting an empty array, I don't understand if I am doing something wring or if it it just not possible. There doesn't seem to be any mention of querying on the admin firestore docs https://firebase.google.com/docs/reference/admin/node/admin.firestore

推荐答案

您不能在任何上下文或任何SDK中使用通配符查询Firestore.这是无效的:

You can't query Firestore with a wildcard in any context or with any SDK. This is invalid:

firestore.collection(`card/{anyCard}/relatedCards`)

如果您要引用文档或集合,则需要提供它的真实,实际路径.您不能通配路径的任何部分.

If you're going to reference a document or collection, you need to provide the real, actual path to it. You can't wildcard any part of the path.

如果您尝试对已知的集合和文档进行更简单的查询,则可以正常工作.

If you try a more simple query for a known collection and document, it will work just fine.

这篇关于我可以在云功能中以通配符作为管理员查询firestore吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆