Flutter:如何限制文档中的字段数
Flutter: How to limit number of fields from a document
我有一个应用程序将数据存储在如下所示的结构中:
Collection > Document (each user has their own) > then a bunch of fields
每次用户输入新条目时,我都会在文档中添加另一个字段。我不知道字段的名称,因为它们是在创建时命名的。我想实现分页,但不知道如何限制文档只给我 x 文档中的字段数。
如何限制从文档返回的字段数?
Each time the user makes a new entry I add another field to the document.
如果您向文档添加新字段,请注意文档有限制。您仅限 1 MiB (1,048,576 bytes) per document。因此,您很可能应该将该数据添加为新文档,而不是文档中的新 属性。
I do not know the name of the fields as they are named by the time they are created.
注意保持在最大限制以下。
I want to implement pagination but do not know how to limit the document to give only give me x number of fields in the document.
分页不是这样的。您可以对查询的结果进行分页,而不是对文档本身进行分页。这意味着您可以执行查询,并且返回的所有结果都可以分成更小的块。我看不出为什么要对单个文档中的数据进行分页。如果这是您的要求,则通过调用 getData() 从文档中获取数据作为 Map,迭代条目,并将它们添加到列表中。然后简单地对该列表进行分页。但我再说一遍,您应该按照文档中的说明使用查询游标对文档进行分页:
我有一个应用程序将数据存储在如下所示的结构中:
Collection > Document (each user has their own) > then a bunch of fields
每次用户输入新条目时,我都会在文档中添加另一个字段。我不知道字段的名称,因为它们是在创建时命名的。我想实现分页,但不知道如何限制文档只给我 x 文档中的字段数。
如何限制从文档返回的字段数?
Each time the user makes a new entry I add another field to the document.
如果您向文档添加新字段,请注意文档有限制。您仅限 1 MiB (1,048,576 bytes) per document。因此,您很可能应该将该数据添加为新文档,而不是文档中的新 属性。
I do not know the name of the fields as they are named by the time they are created.
注意保持在最大限制以下。
I want to implement pagination but do not know how to limit the document to give only give me x number of fields in the document.
分页不是这样的。您可以对查询的结果进行分页,而不是对文档本身进行分页。这意味着您可以执行查询,并且返回的所有结果都可以分成更小的块。我看不出为什么要对单个文档中的数据进行分页。如果这是您的要求,则通过调用 getData() 从文档中获取数据作为 Map,迭代条目,并将它们添加到列表中。然后简单地对该列表进行分页。但我再说一遍,您应该按照文档中的说明使用查询游标对文档进行分页: