Skip to content

Commit

Permalink
Merge pull request #31 from GorgiAstro/28-optional-index-creation
Browse files Browse the repository at this point in the history
create indexes in MongoDB at startup only if env variable (default: true)
  • Loading branch information
jonhealy1 authored Oct 19, 2024
2 parents a4e766c + a1dda88 commit ce94c09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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"
```
Expand Down Expand Up @@ -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.
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)
9 changes: 7 additions & 2 deletions stac_fastapi/mongo/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ce94c09

Please sign in to comment.