From 3dd80b7790153e5a935636f6b47c659fefa52043 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Fri, 24 Jul 2026 21:53:00 +0100 Subject: [PATCH] Updated expandObjectIds function in utils.js to exclude specific fields from expansion, ensuring proper handling of object IDs. Added console.log for debugging filter clauses in getFilter function. --- src/utils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index f08c2d4..2eae32f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1037,6 +1037,7 @@ function flatternObjectIds(object) { } function expandObjectIds(input) { + const excludedFields = ['createdAt', 'updatedAt', 'name', '_id']; // Helper to check if a value is an ObjectId or a 24-char hex string function isObjectId(val) { // Check for MongoDB ObjectId instance @@ -1053,8 +1054,8 @@ function expandObjectIds(input) { } else if (value && typeof value === 'object' && !(value instanceof mongoose.Types.ObjectId)) { var result = {}; for (const [key, val] of Object.entries(value)) { - if (key === '_id') { - // Do not expand keys that are already named _id + if (excludedFields.includes(key)) { + // Do not expand keys that are excluded result[key] = val.toString(); } else if (isObjectId(val)) { result[key] = { _id: val }; @@ -1108,6 +1109,7 @@ function getFilter(query, allowedFilters, parse = true) { clauses.push(parse ? parseFilter(key, value) : { [key]: value }); } } + console.log('clauses', clauses); return mergeFilterClauses(clauses); }