Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ribaraka committed Apr 4, 2022
1 parent cdc5ba9 commit 15185c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
9 changes: 3 additions & 6 deletions internal/handlers/common/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,10 @@ func compareScalars(a, b any) compareResult {

case time.Time:
b, ok := b.(time.Time)
switch {
case ok && a.Unix() != b.Unix():
return compareOrdered(a.Unix(), b.Unix())
case ok && a.Unix() == b.Unix():
return compareOrdered(a.UnixNano(), b.UnixNano())
if !ok {
return notEqual
}
return notEqual
return compareOrdered(a.UnixMilli(), b.UnixMilli())

case types.NullType:
_, ok := b.(types.NullType)
Expand Down
22 changes: 10 additions & 12 deletions internal/handlers/common/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,15 @@ func filterFieldExpr(fieldValue any, expr *types.Document) (bool, error) {
switch exprKey {
case "$eq":
// {field: {$eq: exprValue}}
_, isValueDocument := fieldValue.(*types.Document)
_, isValueArray := fieldValue.(*types.Array)
switch {
case isValueDocument, isValueArray:
return compare(fieldValue, exprValue) == equal, nil

switch fieldValue.(type) {
case *types.Document, *types.Array:
if compare(fieldValue, exprValue) != equal {
return false, nil
}
default:
return compareScalars(fieldValue, exprValue) == equal, nil
if compareScalars(fieldValue, exprValue) != equal {
return false, nil
}
}

case "$ne":
Expand All @@ -181,14 +182,11 @@ func filterFieldExpr(fieldValue any, expr *types.Document) (bool, error) {

case "$gt":
// {field: {$gt: exprValue}}
_, isValueDocument := fieldValue.(*types.Document)
_, isValueArray := fieldValue.(*types.Array)
switch {
case isValueDocument, isValueArray:
switch fieldValue.(type) {
case *types.Document, *types.Array:
if compare(fieldValue, exprValue) != greater {
return false, nil
}

default:
if compareScalars(fieldValue, exprValue) != greater {
return false, nil
Expand Down

0 comments on commit 15185c0

Please sign in to comment.