Skip to content

Commit

Permalink
Fix regression bug in $elemMatch. closes #139
Browse files Browse the repository at this point in the history
  • Loading branch information
kofrasa committed Apr 27, 2020
1 parent 8b4c13d commit b8505e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Loads all Query and Projection operators
*/
import * as booleanOperators from '../operators/expression/boolean'
import * as comparsonOperators from '../operators/expression/comparison'
import * as comparisonOperators from '../operators/expression/comparison'
import { $project, $skip, $limit, $sort } from '../operators/pipeline'
import * as queryOperators from '../operators/query'
import * as projectionOperators from '../operators/projection'
Expand All @@ -15,7 +15,7 @@ import { into } from '../util'
* Enable default operators. This includes only query and projection operators
*/
function enableDefaultOperators() {
useOperators(OperatorType.EXPRESSION, into({}, booleanOperators, comparsonOperators))
useOperators(OperatorType.EXPRESSION, into({}, booleanOperators, comparisonOperators))
useOperators(OperatorType.PIPELINE, { $project, $skip, $limit, $sort })
useOperators(OperatorType.PROJECTION, projectionOperators)
useOperators(OperatorType.QUERY, queryOperators)
Expand Down
4 changes: 3 additions & 1 deletion src/operators/_predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isArray,
isBoolean,
isDate,
isEmpty,
isEqual,
isNil,
isNull,
Expand Down Expand Up @@ -239,7 +240,8 @@ export function $size(a: any[], b: number): boolean {
* @param b {Object} subquery
*/
export function $elemMatch(a: any[], b: object): boolean {
if (a.length > 0) {
// should return false for non-matching input
if (isArray(a) && !isEmpty(a)) {
let format = (x: any) => x
let criteria = b

Expand Down

0 comments on commit b8505e7

Please sign in to comment.