簡體   English   中英

Firestore 查詢:如何過濾文檔 ID?

[英]Firestore query: How to filter on document id?

在 Firestore 中,我有一個包含由時間戳標識的文檔的集合: /records/timestamp
我想根據 id 過濾文檔,使用 javascript 客戶端 API。
我該如何編寫查詢?
我正在尋找以下內容,但找不到id的正確字段名稱:

const query = firestore.collection(`/records`).where("id", "<", 1600766222);

這可以使用 FieldPath.documentId() 實現,但存在限制。

db.collection('CollectionName').where(firebase.firestore.FieldPath.documentId(), '<', '100').get()

但請注意,文檔 ID 是字符串,因此這將包括 ID 為“0”或“1”的文檔,但不包括“2”,因為按字典順序“2”>“100”。

所以如果你想要一個數字查詢,你需要將文檔 ID 作為一個數字字段寫入文檔中,然后對其進行常規查詢。

參考: https://stackoverflow.com/a/48467056/1212903

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM