gpt4 book ai didi

javascript - Firebase startAt 查询给出意外结果

转载 作者:行者123 更新时间:2023-11-28 18:24:39 25 4
gpt4 key购买 nike

我执行以下查询:

firebase.database().ref().child('files').child('54a8924f8c417b2a281f4e3a4c639785/').orderByChild('path').startAt('54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/')

我得到以下输出。奇怪的是,输出还包含我没有在 path 字段中查询的对象:

[
{
"fullPath": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/Test Sub Folder/.Test Sub Folder",
"name": "Test Sub Folder",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/",
"timestamp": 1473150053359,
"type": "dir",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQy_TcuUb3FsQz-CEyY",
"$priority": null
},
{
"extension": "png",
"fullPath": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/download.png",
"mimeType": "image/png",
"name": "download.png",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/",
"size": 124631,
"timestamp": 1473150091860,
"type": "image",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQy_c1SLjHjTHCS1Mox",
"$priority": null
},
{

"extension": "jpg",
"fullPath": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/SampleImage.jpg",
"mimeType": "image/jpeg",
"name": "SampleImage.jpg",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/",
"size": 62678,
"timestamp": 1473150091920,
"type": "image",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQy_c1WiRELh2GiZoFm",
"$priority": null
},
{

"extension": "jpg",
"fullPath": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/goodtimes.jpg",
"mimeType": "image/jpeg",
"name": "goodtimes.jpg",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/",
"size": 128982,
"timestamp": 1473150091920,
"type": "image",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQy_c1_fNhcg3RKXkTj",
"$priority": null
},
{

"extension": "jpg",
"fullPath": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/Test Sub Folder/antibiotics2515.jpg",
"mimeType": "image/jpeg",
"name": "antibiotics2515.jpg",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/Test Sub Folder/",
"size": 430885,
"timestamp": 1473150091921,
"type": "image",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQy_c1bzYINWTYiyFkC",
"$priority": null
},
{

"extension": "png",
"fullPath": "54a8924f8c417b2a281f4e3a4c639785/Test Folder/download.png",
"mimeType": "image/png",
"name": "download.png",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder/",
"size": 124631,
"timestamp": 1473149727313,
"type": "image",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQyZDwJIbSExhaln5l-",
"$priority": null
},
{

"extension": "jpg",
"fullPath": "54a8924f8c417b2a281f4e3a4c639785/Test Folder/SampleImage.jpg",
"mimeType": "image/jpeg",
"name": "SampleImage.jpg",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder/",
"size": 62678,
"timestamp": 1473149727363,
"type": "image",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQyZDwLBEIBKDx6Glq2",
"$priority": null
},
{

"extension": "jpg",
"fullPath": "54a8924f8c417b2a281f4e3a4c639785/Test Folder/goodtimes.jpg",
"mimeType": "image/jpeg",
"name": "goodtimes.jpg",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder/",
"size": 128982,
"timestamp": 1473149728493,
"type": "image",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQyZDwNTejmqwN6X7ZR",
"$priority": null
},
{

"name": "Test Sub Folder",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder/",
"timestamp": 1473149760565,
"type": "dir",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQyZLKsDkxlTJHDDwDX",
"$priority": null
},
{

"extension": "jpg",
"fullPath": "54a8924f8c417b2a281f4e3a4c639785/Test Folder/Test Sub Folder/antibiotics2515.jpg",
"mimeType": "image/jpeg",
"name": "antibiotics2515.jpg",
"path": "54a8924f8c417b2a281f4e3a4c639785/Test Folder/Test Sub Folder/",
"size": 430885,
"timestamp": 1473149889432,
"type": "image",
"uid": "ItvFuIIVriaHPPzeMgggwPqSlmq1",
"$id": "-KQyZqbRe3V1BBWImBxq",
"$priority": null
}
]

输出还包括其他结果,其中 path 为“54a8924f8c417b2a281f4e3a4c639785/Test Folder/”,但我查询了以“”开头的 path >54a8924f8c417b2a281f4e3a4c639785/测试文件夹2/"

最佳答案

Firebase 中的查询在对字符串进行排序/过滤时使用字典顺序。因此,这意味着 测试文件夹/ 实际上大于 测试文件夹 2/,因为 / 大于 (空格).

您需要做的是使用 endAt 子句限制查询。使用高 Unicode 代码点应该允许任何文本,只要前缀相同即可。

.orderByChild('path')
.startAt('54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/')
.endAt('54a8924f8c417b2a281f4e3a4c639785/Test Folder 2/\uf8ff')

旧的 Firebase 文档有一个很好的示例 here在范围查询下,但它似乎在转换中消失了。

关于javascript - Firebase startAt 查询给出意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39344353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com