Skip to content

Commit f41e831

Browse files
committed
Update relays condition to be an array returend
1 parent 5014e36 commit f41e831

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

opensensor/collection_apis.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ def get_relay_board_pipeline(
404404
match_clause = get_initial_match_clause(device_ids, device_name, start_date, end_date)
405405
match_clause["relays"] = {"$exists": True}
406406

407-
# The MongoDB aggregation pipeline for Relay Board data
408407
pipeline = [
409408
{"$match": match_clause},
410409
{
@@ -434,7 +433,13 @@ def get_relay_board_pipeline(
434433
"$project": {
435434
"_id": False,
436435
"timestamp": "$timestamp",
437-
"relays": "$relays",
436+
"relays": {
437+
"$cond": {
438+
"if": {"$isArray": "$relays"},
439+
"then": "$relays",
440+
"else": [{"$ifNull": ["$relays", []]}],
441+
}
442+
},
438443
}
439444
},
440445
{"$sort": {"timestamp": 1}},

0 commit comments

Comments
 (0)