Firestore:查询数组大于运算符 [英] Firestore: Query array with greater than operator

查看:44
本文介绍了Firestore:查询数组大于运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firestore中具有以下数据结构

I have the following data structure in Firestore

- runners (Collection)
-- uid_1 (Document)
--- name: James
--- height: 170
--- weight: 54
--- runTimeInSeconds: [ 540, 533, 530, 500 ] // this is array of 4
-- uid_2 (Document)
--- name: Larry
--- height: 168
--- weight: 51
--- runTimeInSeconds: [ 521, 611, 501 ] // this is array of 3 runs
-- uid_3 (Document)
--- name: Ben
--- height: 180
--- weight: 76
--- runTimeInSeconds: [ 621, 533 ] // this is array of 2 runs

我想按以下顺序获取以下文档(runTimeInSeconds大于600):uid_2后跟uid3.但是我不想看到uid_1.

我应该写什么firestore查询?

我尝试过:

runnersRef.where("runTimeInSeconds", ">", 600) // this does not work.

推荐答案

您不能对列表中的值进行范围查询.为列表项创建的索引不能那样工作.使用array_contains运算符时,它只能检测到列表中的值存在.如果要使用范围运算符,则实际上需要将每个字段列表项目拆分为一个新集合,其中每个项目都有单独的文档.每个文档都应有一个字段,其持续时间字段为数字.然后,您可以将其他字段复制到每个文档中,或者只为跑步者存储对原始文档的引用.

You can't do range queries on values in lists. The index created for list items doesn't work that way. It can only detect that values in lists exist, when using the array_contains operator. If you want to use a range operator, you will actually need to split each field list item into a new collection with separate documents for each item. Each document should have a field with the duration field as a number. You can then duplicate the other fields into each document, or just store a reference to the original document for the runner.

这篇关于Firestore:查询数组大于运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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