Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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
Flutter 如何使用Flatter获取firestore中的最后一个文档id?_Flutter_Google Cloud Firestore_Document - Fatal编程技术网

Flutter 如何使用Flatter获取firestore中的最后一个文档id?

Flutter 如何使用Flatter获取firestore中的最后一个文档id?,flutter,google-cloud-firestore,document,Flutter,Google Cloud Firestore,Document,我需要知道firebase中上次创建的文档的id,因为在我用索引命名文档时,必须上载另一个id更高的文档,所以有没有方法获取上次创建的文档?Firestore没有内置方法获取最近插入的文档。虽然它在元数据中创建文档时进行维护,但它没有用于查询此元数据的API 因此,如果您想知道最近插入了哪个文档,则必须为每个文档添加一个字段,以跟踪该文档创建的时间。您通常会希望使用一个。使用每个文档中的该字段,您可以使用以下内容查找最新文档: collectionRef.orderBy("create

我需要知道firebase中上次创建的文档的id,因为在我用索引命名文档时,必须上载另一个id更高的文档,所以有没有方法获取上次创建的文档?

Firestore没有内置方法获取最近插入的文档。虽然它在元数据中创建文档时进行维护,但它没有用于查询此元数据的API

因此,如果您想知道最近插入了哪个文档,则必须为每个文档添加一个字段,以跟踪该文档创建的时间。您通常会希望使用一个。使用每个文档中的该字段,您可以使用以下内容查找最新文档:

collectionRef.orderBy("createdAt", descending: true).limit(1)