fix(smartdata.classes.doc): Fixed issue with convertFilterForMongoDb to handle array operators.

This commit is contained in:
Philipp Kunz 2024-09-05 15:06:35 +02:00
parent b3e30a8711
commit ea0d2bb251
3 changed files with 12 additions and 2 deletions

View File

@ -1,5 +1,10 @@
# Changelog # Changelog
## 2024-09-05 - 5.2.9 - fix(smartdata.classes.doc)
Fixed issue with convertFilterForMongoDb to handle array operators.
- Updated the convertFilterForMongoDb function in smartdata.classes.doc.ts to properly handle array operators like $in and $all.
## 2024-09-05 - 5.2.8 - fix(smartdata.classes.doc) ## 2024-09-05 - 5.2.8 - fix(smartdata.classes.doc)
Fix key handling in convertFilterForMongoDb function Fix key handling in convertFilterForMongoDb function

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartdata', name: '@push.rocks/smartdata',
version: '5.2.8', version: '5.2.9',
description: 'An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.' description: 'An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.'
} }

View File

@ -53,8 +53,12 @@ export function unI() {
export const convertFilterForMongoDb = (filterArg: { [key: string]: any }) => { export const convertFilterForMongoDb = (filterArg: { [key: string]: any }) => {
const convertedFilter: { [key: string]: any } = {}; const convertedFilter: { [key: string]: any } = {};
const convertFilterArgument = (keyPathArg2: string, filterArg2: any) => { const convertFilterArgument = (keyPathArg2: string, filterArg2: any) => {
if (typeof filterArg2 === 'object') { if (Array.isArray(filterArg2)) {
// Directly assign arrays (they might be using operators like $in or $all)
convertedFilter[keyPathArg2] = filterArg2;
} else if (typeof filterArg2 === 'object' && filterArg2 !== null) {
for (const key of Object.keys(filterArg2)) { for (const key of Object.keys(filterArg2)) {
if (key.startsWith('$')) { if (key.startsWith('$')) {
convertedFilter[keyPathArg2] = filterArg2; convertedFilter[keyPathArg2] = filterArg2;
@ -70,6 +74,7 @@ export const convertFilterForMongoDb = (filterArg: { [key: string]: any }) => {
convertedFilter[keyPathArg2] = filterArg2; convertedFilter[keyPathArg2] = filterArg2;
} }
}; };
for (const key of Object.keys(filterArg)) { for (const key of Object.keys(filterArg)) {
convertFilterArgument(key, filterArg[key]); convertFilterArgument(key, filterArg[key]);
} }