Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

The MongoDB driver failed on nested filter expressions like [['a','=',1], 'or', [['b','=',2], 'and', ['c','=',3]]] while the SQL driver handled them correctly.

Changes

  • Refactored mapFilters into recursive helpers:

    • buildFilterConditions() - processes filter arrays recursively with AND/OR logic
    • buildSingleCondition() - builds individual MongoDB conditions
  • Added heuristic detection - distinguishes criterion [field, op, value] from nested groups by checking if first two elements are strings

  • Proper operator nesting - tracks join state to correctly generate $and/$or at each nesting level

Example

Input filter:

[
  [['status', '=', 'completed'], 'and', ['amount', '>', 100]],
  'or',
  [['customer', '=', 'Alice'], 'and', ['status', '=', 'pending']]
]

Generates:

{
  $or: [
    { $and: [{ status: { $eq: 'completed' } }, { amount: { $gt: 100 } }] },
    { $and: [{ customer: { $eq: 'Alice' } }, { status: { $eq: 'pending' } }] }
  ]
}

Backward compatible with flat filter arrays. Achieves parity with SQL driver using identical recursive approach.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fastdl.mongodb.org
    • Triggering command: /usr/local/bin/node node /home/REDACTED/work/objectql/objectql/node_modules/.bin/../jest/bin/jest.js -- integration.test les/�� (dns block)
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/objectql/objectql/node_modules/.pnpm/jest-worker@30.2.0/node_modules/jest-worker/build/processChild.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Enhancement: Support nested filters in Mongo Driver</issue_title>
<issue_description>## Problem
The current packages/drivers/mongo implementation matches flat arrays but fails on recursive/nested logic (e.g. [['a','=',1], 'or', [['b','=',2], 'and', ['c','=',3]]]), which the SQL driver supports.

Goal

  • Refactor mapFilters in Mongo driver to recursively parse nested arrays.
  • Ensure parity with SQL driver query capabilities.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 12, 2026 21:32
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhancement: Support nested filters in Mongo Driver Add recursive nested filter support to MongoDB driver Jan 12, 2026
Copilot AI requested a review from hotlong January 12, 2026 21:39
@hotlong hotlong requested review from Copilot and removed request for hotlong January 12, 2026 21:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds recursive nested filter support to the MongoDB driver, achieving parity with the SQL driver for complex nested filter expressions.

Changes:

  • Refactored filter handling into recursive helpers (buildFilterConditions and buildSingleCondition)
  • Added heuristic detection to distinguish between single criterion [field, op, value] and nested filter groups
  • Implemented proper operator nesting with $and/$or at each recursion level

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/drivers/mongo/src/index.ts Refactored mapFilters into recursive buildFilterConditions and buildSingleCondition methods with support for nested filter groups and AND/OR operators
packages/drivers/mongo/test/index.test.ts Added unit tests for nested filter groups, deeply nested filters, and implicit AND handling with expected MongoDB query structures
packages/drivers/mongo/test/integration.test.ts Added integration tests for nested and deeply nested filters with real data validation

@hotlong hotlong marked this pull request as ready for review January 12, 2026 22:02
@hotlong hotlong merged commit 00cc010 into main Jan 12, 2026
8 checks passed
@hotlong hotlong deleted the copilot/fix-49200224-1131455451-967f6a5f-1cf1-4bd7-a08c-db452c65dbbd branch January 12, 2026 22:02
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.

Enhancement: Support nested filters in Mongo Driver

2 participants