diff --git a/lib/aggregate.js b/lib/aggregate.js index a1ffb25ddfc..79296807ade 100644 --- a/lib/aggregate.js +++ b/lib/aggregate.js @@ -1100,13 +1100,13 @@ if (Symbol.asyncIterator != null) { */ function isOperator(obj) { - if (typeof obj !== 'object') { + if (typeof obj !== 'object' || obj === null) { return false; } const k = Object.keys(obj); - return k.length === 1 && k.some(key => { return key[0] === '$'; }); + return k.length === 1 && k[0][0] === '$'; } /*! diff --git a/lib/helpers/query/isOperator.js b/lib/helpers/query/isOperator.js index 3b9813920ff..04488591a6c 100644 --- a/lib/helpers/query/isOperator.js +++ b/lib/helpers/query/isOperator.js @@ -7,5 +7,8 @@ const specialKeys = new Set([ ]); module.exports = function isOperator(path) { - return path.startsWith('$') && !specialKeys.has(path); -}; \ No newline at end of file + return ( + path[0] === '$' && + !specialKeys.has(path) + ); +};