Skip to content

Fix using "$not" as top-level operator in output to MongoDb#1254

Merged
ukrbublik merged 24 commits intomasterfrom
fix-not-mongo-1206
May 12, 2025
Merged

Fix using "$not" as top-level operator in output to MongoDb#1254
ukrbublik merged 24 commits intomasterfrom
fix-not-mongo-1206

Conversation

@ukrbublik
Copy link
Copy Markdown
Owner

@ukrbublik ukrbublik commented May 11, 2025

Fixes #1250

  • For negation now we use $not only in allowed places in query, otherwide use {$nor: [a]} instead of {$not: a}
  • Added support of exportPreserveGroups for mongo output
  • To use Date in output MongoDb query we need to use $dateFromString (or $toDate).
    But it's supported only inside $expr (so resulted query will be a bit longer)
  • Refactoring: Added MongoUtils, JsonLogicUtils , SpelUtils to Utils (extracted from core/modules/utils/export.js). MongoUtils also now owns mongoFormatOp1 and mongoFormatOp2. Added mongoFieldEscape to MongoUtils to prevent using of $ in field names that comed from config
  • Demo optimization: call format* functions only once at init (see using of areConfigsSame) and only once on loading new data or clicking Reload (see memoized func-components at examples/src/demo/blocks/output.tsx)
  • Changed args of mongoFormatOp function - from field, op, val, useExpr, .. to field, op, val, not, useExpr, ..
    Handling not in mongoFormatOp is a best place
  • Fixed cutting of group field from child fields when exporting to simple query string (see packages/core/modules/export/queryString.js)
  • Checked manually mongo queries from tests in MongoDB playground - now returns no errors

Rules of mongo regarding $not and $nor considered for this PR:

  • can't use $expr inside $filter.cond or inside $elemMatch
  • $elemMatch can't have $not and $expr inside BUT can have $nor
  • $nor can't be inside $filter.cond or $expr

Also rules for inside $expr:

  • $nin can't be used
  • Instead of $regex we should use $regexFind

@codesandbox
Copy link
Copy Markdown

codesandbox Bot commented May 11, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-awesome-query-builder-examples ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2025 10:05pm
react-awesome-query-builder-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2025 10:05pm
react-awesome-query-builder-sandbox-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2025 10:05pm

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented May 11, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 6d02dd7:

Sandbox Source
@react-awesome-query-builder/examples Configuration
@react-awesome-query-builder/sandbox Configuration
@react-awesome-query-builder/sandbox-simple Configuration
@react-awesome-query-builder/sandbox-next Configuration

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2025

Codecov Report

Attention: Patch coverage is 75.77640% with 39 lines in your changes missing coverage. Please review.

Project coverage is 80.77%. Comparing base (81092f5) to head (ffc5fef).

Files with missing lines Patch % Lines
packages/core/modules/utils/spelUtils.js 69.11% 21 Missing ⚠️
packages/core/modules/utils/jsonLogicUtils.js 12.50% 14 Missing ⚠️
packages/core/modules/utils/mongoUtils.js 90.32% 3 Missing ⚠️
packages/core/modules/export/mongoDb.js 97.05% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1254      +/-   ##
==========================================
+ Coverage   80.73%   80.77%   +0.03%     
==========================================
  Files         223      225       +2     
  Lines       12179    12213      +34     
  Branches     1544     1544              
==========================================
+ Hits         9833     9865      +32     
- Misses       1605     1610       +5     
+ Partials      741      738       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ukrbublik ukrbublik requested a review from Copilot May 12, 2025 21:59
Copy link
Copy Markdown

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 PR fixes issues related to MongoDB output formatting. Key changes include the proper handling of the top‐level "$not" operator by switching to "$nor" in appropriate contexts and using a $dateFromString conversion with the correct date format.

  • Updated test cases to use "$regexFind" for MongoDB.
  • Revised widget configurations and export utilities for consistent MongoDB and SpEL formatting.
  • Enhanced MongoDB query generation by escaping field names and adjusting negation handling.

Reviewed Changes

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

Show a summary per file
File Description
packages/tests/specs/FuncAtLhs.test.ts Updates regex operator usage to "$regexFind"
packages/examples/src/demo_switch/spel_concat.tsx Migrates deprecated concatenation methods to new Spel utils
packages/examples/src/demo/index.tsx Refactors state update with explicit tree and config assignment
packages/examples/src/demo/config/index.tsx Adjusts MongoDB date conversion to use "$dateFromString"
packages/core/modules/export/mongoDb.js Switches from "$not" to "$nor" where appropriate in MongoDB query
packages/core/modules/utils/* Various refactors to utilize updated utils and method exports
Comments suppressed due to low confidence (2)

packages/examples/src/demo/config/index.tsx:879

  • Replacing dateVal.toDate() with a $dateFromString conversion ensures aggregation compatibility. Verify that the provided date format ('YYYY-MM-DD' and '%Y-%m-%d') meets MongoDB's parsing requirements.
if (dateVal.isValid()) {

packages/core/modules/export/mongoDb.js:237

  • Using '$nor' as a replacement for top-level '$not' operator must be validated for all contexts. Confirm that wrapping the query with '$nor' in non-$filter scenarios behaves as expected in MongoDB.
resultQuery = { "$nor": [ resultQuery ] };

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.

$not at top level is not allowed in mongo.

2 participants