Firestore查询:如何对文档id进行筛选



在Firestore中,我有一个包含由时间戳标识的文档的集合:/records/timestamp
我想使用javascript客户端API根据id筛选文档
如何编写查询
我正在沿着下面的行寻找一些东西,但我找不到id的正确字段名:

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

使用FieldPath.docentId((可以做到这一点,但也有局限性。

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

但请注意,文档ID是字符串,因此这将包括ID为"0"或"1"的文档,但不包括自"2"以来的"2"&gt100’。

因此,如果你想要一个数字查询,你需要将文档ID写为文档中的数字字段,然后对其进行正常查询

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

最新更新