Skip to content

Commit 1e424df

Browse files
committed
add limited and count
1 parent c76cbf1 commit 1e424df

File tree

1 file changed

+7
-3
lines changed
  • stac_fastapi/mongo/stac_fastapi/mongo

1 file changed

+7
-3
lines changed

stac_fastapi/mongo/stac_fastapi/mongo/core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ def item_collection(
105105
with self.client.start_session() as session:
106106
collection_children = self.item_table.find(
107107
{"collection": collection_id}, session=session
108-
).sort(
108+
).limit(limit).sort(
109109
[("properties.datetime", pymongo.ASCENDING), ("id", pymongo.ASCENDING)]
110110
)
111111

112+
matched = self.item_table.count_documents({"collection": collection_id})
113+
112114
for item in collection_children:
113115
response_features.append(
114116
self.item_serializer.db_to_stac(item, base_url=base_url)
@@ -120,7 +122,7 @@ def item_collection(
120122
context_obj = {
121123
"returned": count if count <= 10 else limit,
122124
"limit": limit,
123-
"matched": len(response_features) or None,
125+
"matched": matched or None,
124126
}
125127

126128
return ItemCollection(
@@ -296,6 +298,8 @@ def post_search(
296298
.sort(sort_list)
297299
)
298300

301+
matched = self.item_table.count_documents(queries)
302+
299303
results = []
300304
links = []
301305

@@ -329,7 +333,7 @@ def post_search(
329333
context_obj = {
330334
"returned": count if count <= 10 else search_request.limit,
331335
"limit": search_request.limit,
332-
"matched": len(results) or None,
336+
"matched": matched or None,
333337
}
334338

335339
return ItemCollection(

0 commit comments

Comments
 (0)