Firestore查询文档以字符串开头 [英] Firestore query documents startsWith a string

查看:112
本文介绍了Firestore查询文档以字符串开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以查询一个firestore集合来获取开头的所有文档?



我已经阅读了文档但没有找到任何合适的查询。

解决方案

你可以但它很棘手。您需要搜索大于或等于所需字符串且小于后继密钥的文档。



例如,要查找包含字段'foo'盯着'bar'你会查询:



<$ p $ ('foo','''''''''''')
。 ,'bas');

这实际上是一种我们在客户端实现中用于扫描匹配路径的文档集合的技术。我们的继任关键计算是由扫描仪正在寻找以当前用户ID开头的所有密钥。


Is it possible to query a firestore collection to get all document that starts with a specific string?

I have gone through the documentation but do not find any suitable query for this.

解决方案

You can but it's tricky. You need to search for documents greater than or equal to the string you want and less than a successor key.

For example, to find documents containing a field 'foo' staring with 'bar' you would query:

db.collection(c)
    .where('foo', '>=', 'bar')
    .where('foo', '<', 'bas');

This is actually a technique we use in the client implementation for scanning collections of documents matching a path. Our successor key computation is called by a scanner which is looking for all keys starting with the current user id.

这篇关于Firestore查询文档以字符串开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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