Skip to content

Commit

Permalink
Make it possible to drop collections by API (skyportal#170)
Browse files Browse the repository at this point in the history
This PR makes it possible to drop collections by API.
  • Loading branch information
mcoughlin authored Aug 22, 2022
1 parent a1d9c4b commit f61c28d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions kowalski/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ async def users_put(request: web.Request) -> web.Response:
"aggregate",
"info",
"near",
"drop",
)
INFO_COMMANDS = (
"catalog_names",
Expand Down Expand Up @@ -1153,6 +1154,13 @@ async def post(self, request: web.Request) -> web.Response:
"filter": {"objectId": "ZTF20aakyoez"}
}
drop:
value:
"query_type": "drop"
"query": {
"catalog": "ZTF_alerts",
}
estimated_document_count:
value:
"query_type": "estimated_document_count"
Expand Down Expand Up @@ -1265,6 +1273,12 @@ async def post(self, request: web.Request) -> web.Response:
"message": "Successfully executed query"
"data": 1
drop:
value:
"status": "success"
"message": "Successfully dropped collection"
"data": 1
estimated_document_count:
value:
"status": "success"
Expand Down Expand Up @@ -1332,6 +1346,12 @@ async def post(self, request: web.Request) -> web.Response:
# execute query, depending on query.query_type
data = dict()

if query.query_type == "drop":
catalog = query.query["catalog"]
cursor = request.app["mongo"][catalog].drop()
data = await cursor
return self.success(message="Successfully dropped collection", data=data)

if query.query_type in ("cone_search", "near"):
# iterate over catalogs
for catalog in query.query:
Expand Down

0 comments on commit f61c28d

Please sign in to comment.