首页 > 解决方案 > 我如何在firebase中使用.where?

问题描述

我有这部分代码来获取集合火力库

const db = getFirestore(app)
const getCollection = name => collection(db, name)
const collection = getCollection(db, 'chars')
const query = await collection.where('name', '==', value)

我收到错误.where不是函数,怎么了?

未处理的拒绝(TypeError):collection.where 不是函数

标签: reactjsfirebase

解决方案


您正在使用新的模块化 SDK,其中所有功能都是顶级的。

要创建查询,请执行以下操作:

const query = query(collection, where('name', '==', value))

另请参阅有关构建查询的 Firebase 文档。


推荐阅读