Skip to content

Commit 1659828

Browse files
authored
Merge pull request #15 from jonhealy1/fix_limit
add limited and count
2 parents c76cbf1 + 7a7cd13 commit 1659828

File tree

1 file changed

+15
-6
lines changed
  • stac_fastapi/mongo/stac_fastapi/mongo

1 file changed

+15
-6
lines changed

stac_fastapi/mongo/stac_fastapi/mongo/core.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,19 @@ def item_collection(
103103
base_url = str(kwargs["request"].base_url)
104104

105105
with self.client.start_session() as session:
106-
collection_children = self.item_table.find(
107-
{"collection": collection_id}, session=session
108-
).sort(
109-
[("properties.datetime", pymongo.ASCENDING), ("id", pymongo.ASCENDING)]
106+
collection_children = (
107+
self.item_table.find({"collection": collection_id}, session=session)
108+
.limit(limit)
109+
.sort(
110+
[
111+
("properties.datetime", pymongo.ASCENDING),
112+
("id", pymongo.ASCENDING),
113+
]
114+
)
110115
)
111116

117+
matched = self.item_table.count_documents({"collection": collection_id})
118+
112119
for item in collection_children:
113120
response_features.append(
114121
self.item_serializer.db_to_stac(item, base_url=base_url)
@@ -120,7 +127,7 @@ def item_collection(
120127
context_obj = {
121128
"returned": count if count <= 10 else limit,
122129
"limit": limit,
123-
"matched": len(response_features) or None,
130+
"matched": matched or None,
124131
}
125132

126133
return ItemCollection(
@@ -296,6 +303,8 @@ def post_search(
296303
.sort(sort_list)
297304
)
298305

306+
matched = self.item_table.count_documents(queries)
307+
299308
results = []
300309
links = []
301310

@@ -329,7 +338,7 @@ def post_search(
329338
context_obj = {
330339
"returned": count if count <= 10 else search_request.limit,
331340
"limit": search_request.limit,
332-
"matched": len(results) or None,
341+
"matched": matched or None,
333342
}
334343

335344
return ItemCollection(

0 commit comments

Comments
 (0)