Skip to content

Commit

Permalink
Merge pull request #11400 from Uzlopak/improve-aggregate-isOperator
Browse files Browse the repository at this point in the history
impr: isOperator
  • Loading branch information
vkarpov15 authored Feb 15, 2022
2 parents 96c067e + ea9d7fc commit 0221233
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] === '$';
}

/*!
Expand Down
7 changes: 5 additions & 2 deletions lib/helpers/query/isOperator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ const specialKeys = new Set([
]);

module.exports = function isOperator(path) {
return path.startsWith('$') && !specialKeys.has(path);
};
return (
path[0] === '$' &&
!specialKeys.has(path)
);
};

0 comments on commit 0221233

Please sign in to comment.