本文介绍了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 比较运算符 - 包含、不包含、以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:50