Skip to content

Fix APIv3 multi-parameter filter aggregation for range queries#2

Open
sergev-art wants to merge 1 commit intomasterfrom
fix/apiv3-filter-aggregation
Open

Fix APIv3 multi-parameter filter aggregation for range queries#2
sergev-art wants to merge 1 commit intomasterfrom
fix/apiv3-filter-aggregation

Conversation

@sergev-art
Copy link
Copy Markdown
Owner

Summary

Fixes a bug where APIv3 discarded all but the last filter parameter for a given field, breaking range queries like date$gt=X&date$lt=Y. Filter parameters are now properly aggregated into a compound MongoDB query.

  • Root cause: parseFilter replaced the filter object for each parameter instead of merging
  • Fix: Aggregates multiple filter operators for the same field into a single query object
  • Tests: Adds verification tests for range queries and ISO8601 date filtering

Upstream: nightscout#8252

Design Control Impact

Modified Requirements

  • API query specification (SR-level): Multi-parameter filtering on the same field shall aggregate operators, not replace them
  • Date handling: APIv3 shall accept ISO8601 date strings in filter parameters

New Test Cases

  • Range query: date$gt=X&date$lt=Y returns only entries within range
  • ISO8601 date filter: date strings accepted and correctly parsed
  • Single-field multi-operator: compound filters produce correct MongoDB query

Risk Items

  • Data integrity: Incorrect filtering could return wrong glucose readings to clients/caregivers — incorrect treatment decisions could follow
  • Silent failure: The bug produced no error — it simply returned a superset of requested data

Files Changed (2)

File Change Lines
lib/api3/storage/mongoCollection/utils.js Fix filter aggregation logic +19/-17
tests/api3.search.test.js New range query and date tests +77/-0

Previously, only the last filter parameter for a field would be applied.
After this change, filter parameters for fields are aggregated instead
of being replaced.

Additional tests were added to both verify the new behavior as well as
to verify other documented API functionality, such as the use of ISO8601
dates.

This allows for range queries, ex: date$gt=1491719030000&date$lt=1491719930000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants