Skip to content

add limited and count #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions stac_fastapi/mongo/stac_fastapi/mongo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,19 @@ def item_collection(
base_url = str(kwargs["request"].base_url)

with self.client.start_session() as session:
collection_children = self.item_table.find(
{"collection": collection_id}, session=session
).sort(
[("properties.datetime", pymongo.ASCENDING), ("id", pymongo.ASCENDING)]
collection_children = (
self.item_table.find({"collection": collection_id}, session=session)
.limit(limit)
.sort(
[
("properties.datetime", pymongo.ASCENDING),
("id", pymongo.ASCENDING),
]
)
)

matched = self.item_table.count_documents({"collection": collection_id})

for item in collection_children:
response_features.append(
self.item_serializer.db_to_stac(item, base_url=base_url)
Expand All @@ -120,7 +127,7 @@ def item_collection(
context_obj = {
"returned": count if count <= 10 else limit,
"limit": limit,
"matched": len(response_features) or None,
"matched": matched or None,
}

return ItemCollection(
Expand Down Expand Up @@ -296,6 +303,8 @@ def post_search(
.sort(sort_list)
)

matched = self.item_table.count_documents(queries)

results = []
links = []

Expand Down Expand Up @@ -329,7 +338,7 @@ def post_search(
context_obj = {
"returned": count if count <= 10 else search_request.limit,
"limit": search_request.limit,
"matched": len(results) or None,
"matched": matched or None,
}

return ItemCollection(
Expand Down