Skip to content

Commit

Permalink
Update relays condition to be an array returend
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Oct 6, 2024
1 parent 5014e36 commit f41e831
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions opensensor/collection_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ def get_relay_board_pipeline(
match_clause = get_initial_match_clause(device_ids, device_name, start_date, end_date)
match_clause["relays"] = {"$exists": True}

# The MongoDB aggregation pipeline for Relay Board data
pipeline = [
{"$match": match_clause},
{
Expand Down Expand Up @@ -434,7 +433,13 @@ def get_relay_board_pipeline(
"$project": {
"_id": False,
"timestamp": "$timestamp",
"relays": "$relays",
"relays": {
"$cond": {
"if": {"$isArray": "$relays"},
"then": "$relays",
"else": [{"$ifNull": ["$relays", []]}],
}
},
}
},
{"$sort": {"timestamp": 1}},
Expand Down

0 comments on commit f41e831

Please sign in to comment.