Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase Firestore查询:如何筛选文档id?_Firebase - Fatal编程技术网

Firebase Firestore查询:如何筛选文档id?

Firebase Firestore查询:如何筛选文档id?,firebase,Firebase,在Firestore中,我有一个包含时间戳标识的文档的集合:/records/timestamp 我想使用javascript客户端API根据id筛选文档。 如何编写查询? 我正在沿着以下行查找内容,但找不到id的正确字段名: const query=firestore.collection(`/records`)。其中(“id”),这可以使用FieldPath.documentId()实现,但有一些限制 db.collection('CollectionName').where(firebas

在Firestore中,我有一个包含时间戳标识的文档的集合:
/records/timestamp

我想使用javascript客户端API根据id筛选文档。
如何编写查询?
我正在沿着以下行查找内容,但找不到id的正确字段名:


const query=firestore.collection(`/records`)。其中(“id”),这可以使用FieldPath.documentId()实现,但有一些限制

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

db.collection('CollectionName')。其中(firebase.firestore.FieldPath.documentId(),”这可以使用FieldPath.documentId(),但有一些限制

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

db.collection('CollectionName')。where(firebase.firestore.FieldPath.documentId(),'我建议将时间戳保存为一个字段,因为您可以对其进行排序并将其存储为一个数字。但是如果您确实需要字符串ID用于其他目的,请使用us FieldPath.documentId()。谢谢您的评论。当您提到排序时,您不认为可以执行
查询.orderBy(FieldPath.documentId())
?是的,但这将按照字符串的排序方式进行排序。我想您应该按照它们的来序而不是字符串值(ASCII值)的顺序进行排序。将来当您有大量数据时,您可能需要添加一个新功能,该功能使用时间戳作为一个数字,这将是一个令人头痛的问题。我建议将时间戳保存为一个字段,因为您可以对其进行排序并将其存储为一个数字。但如果您确实需要字符串ID用于其他目的,请使用us FieldPath.documentId()。谢谢您的评论。当您提到排序时,您不认为可以执行
查询.orderBy(FieldPath.documentId())
?是的,但这将按照字符串的排序方式进行排序。我想您应该按照它们的来序而不是字符串值(ASCII值)的顺序进行排序。将来,当您有大量数据时,您可能会希望添加一个新功能,该功能使用时间戳作为数字,修复完美将是一件令人头痛的事情!我将坚持使用文档id而不是字段,因为我对字典排序很好,因为我只处理时间戳。您会做其他事情吗?完美!我将继续使用我喜欢使用文档id而不是字段,因为我对词典排序很在行,因为我只处理时间戳。你会这样做吗?