Skip to content

Commit 150617a

Browse files
Copilothotlong
andcommitted
Fix FilterNode converter: properly handle NOT operator and reduce code duplication
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent d37d03c commit 150617a

1 file changed

Lines changed: 12 additions & 25 deletions

File tree

packages/drivers/mongo/src/index.ts

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -579,41 +579,28 @@ export class MongoDriver implements Driver, DriverInterface {
579579
return [[node.field, operator, node.value]];
580580

581581
case 'and':
582-
// Convert AND node to array with 'and' separator
583-
if (!node.children || node.children.length === 0) return undefined;
584-
const andResults: any[] = [];
585-
for (const child of node.children) {
586-
const converted = this.convertFilterNodeToLegacy(child);
587-
if (converted) {
588-
if (andResults.length > 0) {
589-
andResults.push('and');
590-
}
591-
andResults.push(...(Array.isArray(converted) ? converted : [converted]));
592-
}
593-
}
594-
return andResults.length > 0 ? andResults : undefined;
595-
596582
case 'or':
597-
// Convert OR node to array with 'or' separator
583+
// Convert AND/OR node to array with separator
598584
if (!node.children || node.children.length === 0) return undefined;
599-
const orResults: any[] = [];
585+
const results: any[] = [];
586+
const separator = node.type; // 'and' or 'or'
587+
600588
for (const child of node.children) {
601589
const converted = this.convertFilterNodeToLegacy(child);
602590
if (converted) {
603-
if (orResults.length > 0) {
604-
orResults.push('or');
591+
if (results.length > 0) {
592+
results.push(separator);
605593
}
606-
orResults.push(...(Array.isArray(converted) ? converted : [converted]));
594+
results.push(...(Array.isArray(converted) ? converted : [converted]));
607595
}
608596
}
609-
return orResults.length > 0 ? orResults : undefined;
597+
return results.length > 0 ? results : undefined;
610598

611599
case 'not':
612-
// NOT is complex - we'll just process the first child for now
613-
if (node.children && node.children.length > 0) {
614-
return this.convertFilterNodeToLegacy(node.children[0]);
615-
}
616-
return undefined;
600+
// NOT is not directly supported in the legacy filter format
601+
// MongoDB supports $not, but legacy array format doesn't have a NOT operator
602+
// We'll throw an error to indicate this limitation
603+
throw new Error('NOT filters are not supported in legacy filter format. Use native MongoDB queries with $not operator instead.');
617604

618605
default:
619606
return undefined;

0 commit comments

Comments
 (0)