From 3053c61653b26995713de11f8e812837c03bda5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jonglez?= Date: Thu, 10 Oct 2024 14:45:25 +0200 Subject: [PATCH 1/3] create indexes in MongoDB at startup only if env variable (default: true) --- stac_fastapi/mongo/app.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stac_fastapi/mongo/app.py b/stac_fastapi/mongo/app.py index acc8a40..22d699c 100644 --- a/stac_fastapi/mongo/app.py +++ b/stac_fastapi/mongo/app.py @@ -1,5 +1,7 @@ """FastAPI application.""" +import os + from stac_fastapi.api.app import StacApi from stac_fastapi.api.models import create_get_request_model, create_post_request_model from stac_fastapi.core.basic_auth import apply_basic_auth @@ -77,8 +79,11 @@ @app.on_event("startup") async def _startup_event() -> None: - await create_collection_index() - await create_item_index() + if ( + os.getenv("MONGO_CREATE_INDEXES", "true") == "true" + ): # Boolean env variables in docker compose are actually strings + await create_collection_index() + await create_item_index() def run() -> None: From b79729611819b0481253df33f4c215004f38914e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jonglez?= Date: Wed, 16 Oct 2024 12:45:41 +0200 Subject: [PATCH 2/3] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c24b375..1919ba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0/ - Add support for python 3.12. [#22](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/22) - Updated sfeos core to v3.0.0a0, fixed datetime functionality. [#23](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/23) +- Create indexes in MongoDB at startup only if environment variable MONGO_CREATE_INDEXES is set to "true" (default when the env variable is not set: "true"). [#31](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/31) ### Fixed From a1dda8838f8a56be41be4dadb78dd589328c39a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Jonglez?= Date: Thu, 17 Oct 2024 11:27:28 +0200 Subject: [PATCH 3/3] update README.md --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7d32e43..9605348 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # stac-fastapi-mongo -## Mongo backend for the stac-fastapi project built on top of the [sfeos](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch) core api library. +## Mongo backend for the stac-fastapi project built on top of the [sfeos](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch) core api library. [![PyPI version](https://badge.fury.io/py/stac-fastapi.mongo.svg)](https://badge.fury.io/py/stac-fastapi.mongo) [![Join the chat at https://gitter.im/stac-fastapi-mongo/community](https://badges.gitter.im/stac-fastapi-mongo/community.svg)](https://gitter.im/stac-fastapi-mongo/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -39,7 +39,7 @@ pre-commit run --all-files docker-compose up mongo docker-compose build app-mongo ``` - + ## Running Mongo API on localhost:8084 ```shell @@ -56,15 +56,15 @@ curl -X "POST" "http://localhost:8084/collections" \ }' ``` -Note: this "Collections Transaction" behavior is not part of the STAC API, but may be soon. +Note: this "Collections Transaction" behavior is not part of the STAC API, but may be soon. ## Collection pagination The collections route handles optional `limit` and `token` parameters. The `links` field that is -returned from the `/collections` route contains a `next` link with the token that can be used to +returned from the `/collections` route contains a `next` link with the token that can be used to get the next page of results. - + ```shell curl -X "GET" "http://localhost:8084/collections?limit=1&token=example_token" ``` @@ -159,4 +159,8 @@ Example: This example demonstrates the configuration for public endpoints, allow ### Basic Authentication Configurations -See `docker-compose.basic_auth_protected.yml` and `docker-compose.basic_auth_public.yml` for basic authentication configurations. \ No newline at end of file +See `docker-compose.basic_auth_protected.yml` and `docker-compose.basic_auth_public.yml` for basic authentication configurations. + +## Note for read-only databases + +If you are using a read-only MongoDB user, the `MONGO_CREATE_INDEXES` environment variable should be set to "false" (as a string and not a boolean) to avoid creating indexes in the database. When this environment variable is not set, the default is to create indexes. See [Github issue #28](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/issues/28)