限制PythonEve rest api框架中的数据选择



我想从类似的api端点返回前100行

localhost/products?limit=100
localhost/products?aggregate={"$limit": 100}

这可能和夏娃有关吗?

是的,你可以这样做:

localhost/products?max_results=100

如果您愿意,您可以在设置中使用QUERY_MAX_RESULTS = 'limit'max_results切换到limit。此外,还要注意其他有用的分页设置:

PAGINATION_LIMIT
Maximum value allowed for QUERY_MAX_RESULTS query parameter. Values exceeding the limit will be silently replaced with this value. You want to aim for a reasonable compromise between performance and transfer size. Defaults to 50.
PAGINATION_DEFAULT
Default value for QUERY_MAX_RESULTS. Defaults to 25.
OPTIMIZE_PAGINATION_FOR_SPEED
Set this to True to improve pagination performance. When optimization is active no count operation, which can be slow on large collections, is performed on the database. This does have a few consequences. Firstly, no document count is returned. Secondly, HATEOAS is less accurate: no last page link is available, and next page link is always included, even on last page. On big collections, switching this feature on can greatly improve performance. Defaults to False (slower performance; document count included; accurate HATEOAS).
QUERY_MAX_RESULTS
Key for the max results query parameter. Defaults to max_results.

还有更多可用的设置,只需查看文档即可。

最新更新