【问题标题】:Can I use where key in firestore without matching the string [duplicate]我可以在firestore中使用where键而不匹配字符串吗?
【发布时间】:2021-06-29 08:38:08
【问题描述】:

我在 firebase 中有一些文件,例如:

{name:'hasaduzzaman'}
{name:'himel'}

我有类似的 firebase 查询:

const [searchtext,setSearchText] = useState('')
let collectionRef = firestore.collection('users');
collectionRef.where('name', '==', searchText) // This is comming from the state of react hooks

我的主要观点是,如果 searchText 与用户的全名不匹配,它不会返回任何内容。有没有办法使用where键而不匹配用户的全名

【问题讨论】:

  • Firestore 无法执行全文搜索。它可以执行所谓的 prefix 搜索,通过执行以下操作返回名称 以* 某个子字符串开头的文档:collectionRef.where('name', ">=", "him").where('name', "<", "hin")。如果您需要更精细的搜索,请考虑另一种/额外的解决方案。

标签: reactjs firebase google-cloud-firestore


【解决方案1】:

在 firebase 的情况下,这是不可用的。我也有类似的担忧,但通过使用标签创建了一个解决方法。我猜你可以使用 algolia 服务

即使他们有关于相同的官方文档

firestore algolia docs

【讨论】:

    猜你喜欢
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 1970-01-01
    • 2018-03-11
    • 2011-08-14
    • 1970-01-01
    相关资源
    最近更新 更多