Firestore比较运算符-包含,不包含,开头为 [英] Firestore Comparison Operators - contains, does not contain, starts with

查看:71
本文介绍了Firestore比较运算符-包含,不包含,开头为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档".... where()方法采用三个参数:要过滤的字段,比较操作和值.比较可以是<,< =,==,>或> = ..."

From the documentation "...The where() method takes three parameters: a field to filter on, a comparison operation, and a value. The comparison can be <, <=, ==, >, or >=..."

我们需要执行的查询是:

The queries that we need to carry out are:

  • 等于(==)
  • 不等于(???)
  • 小于(<)
  • 大于(>)
  • 小于或等于(< =)
  • 大于或等于(> =)
  • 包含(???)
  • 不包含(???)
  • 以(???)开头

在此问题中,建议是实施一个全文搜索,例如Elastic或Algolia.我不需要全文搜索-我只需要这些基本运算符即可在指定字段中进行搜索.但是更大的问题是我的应用程序在相当长的一段时间内处于脱机状态,并且我们缓存了需要脱机的数据,并且脱机的全文本搜索不是一种选择(除非您获得了Enterprise($$ $$$$)Algolia的许可证-但对于我们正在寻找的内容来说似乎仍然有些过分.)

In this question the suggestion is to implement a full text search such as Elastic or Algolia. I don't need full text search - I just need these basic operators to search in nominated fields. But the bigger problem I have is that my app is off-line for substantial periods of time and we cache the data we need off-line and off-line full text search is not an option (except if you get the Enterprise ($$$$$$) license of Algolia - but still seems like overkill for what we are looking for).

请问您对"???"时where("FIELD","???","string")有什么解决方案吗?是不等于",包含",不包含"或以...开头"?

Do any of you have any solutions for where("FIELD", "???", "string") when "???" is "not equal to", "contains", "does not contain", or "starts with"?

感谢任何想法.

推荐答案

Cloud Firestore中没有本地包含",不包含",开头为"或结尾为"的查询.

There are no native "contains", "does not contain", "starts with" or "ends with" queries in Cloud Firestore.

您可以使用<>来估计非常有限的开头为"查询,但是:

You can approximate a very limited "starts with" query using < and >, however:

// All names starting with "Sa"
db.collection("people")
  .where("name", ">", "Sa")
  .where("name", "<", "Saz")

这篇关于Firestore比较运算符-包含,不包含,开头为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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