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); }