Skip to content

Commit

Permalink
switch back to mongoose.Types.ObjectId
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfrase3 committed Mar 6, 2024
1 parent d4d720d commit 1443088
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/hooks/distinct.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const castObjectIds = (val) => {
if(Array.isArray(val) && val.length !== 24) return val.map(castObjectIds);
const stringVal = (val && val.toJSON && val.toJSON()) || `${val}`;
if(isoReg.test(stringVal)) return new Date(stringVal);
if(/^[abcdefABCDEF\d]{24}$/.test(stringVal)) return new mongoose.ObjectId(stringVal);
if(/^[abcdefABCDEF\d]{24}$/.test(stringVal)) return new mongoose.Types.ObjectId(stringVal);
if(Array.isArray(val)) return val.map(castObjectIds);
if (!val) return val;
if(typeof val === 'object') return Object.keys(val).reduce((a, i) => ({...a, [i]: castObjectIds(val[i])}), {});
Expand Down Expand Up @@ -55,6 +55,9 @@ module.exports = function (excludeFields = []) {
}
if (!$distinct) return context;

if (filters.$and) query.$and = filters.$and;
if (filters.$or) query.$or = filters.$or;

// Throw error if field is restricted
if (excludeFields.some(field => {
return field === $distinct
Expand Down

0 comments on commit 1443088

Please sign in to comment.