2016-09-06 63 views
0

我執行以下查詢:火力地堡startAt查詢給人意想不到的效果

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

而且我得到以下輸出。這是奇怪的是輸出也包含我還沒有在路徑現場查詢這些對象:

[ 
    { 
     "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/Test Folder 2/

回答

3

Firebase中的查詢在對字符串進行排序/過濾時使用了詞典排序。因此,這意味着Test Folder/實際上大於Test Folder 2/,因爲/大於(space)

你所要做的就是用endAt子句來限制查詢。只要前綴相同,使用高Unicode代碼點應允許任何文本。

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

老火力地堡文件曾經對自己here下的範圍查詢一個很好的例子,但似乎過渡到已經消失。

+0

非常感謝@vzsg,工作完美。 –