Skip to content

Commit 42a9298

Browse files
committed
Fix: take val as any type in mongodb
1 parent 3831d53 commit 42a9298

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

drivers/mongodb/internal/backfill.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -397,23 +397,30 @@ func buildMongoCondition(cond types.Condition) bson.D {
397397
"=": "$eq",
398398
"!=": "$ne",
399399
}
400-
//TODO: take val as any type
401-
value := func(field, val string) interface{} {
400+
401+
value := func(field string, val any) interface{} {
402402
// Handle unquoted null
403-
if val == "null" {
403+
switch v := val.(type) {
404+
case nil:
404405
return nil
405-
}
406+
case string:
407+
if v == "null" {
408+
return nil
409+
}
406410

407-
if strings.HasPrefix(val, "\"") && strings.HasSuffix(val, "\"") {
408-
val = val[1 : len(val)-1]
409-
}
410-
if field == "_id" && len(val) == 24 {
411-
if oid, err := primitive.ObjectIDFromHex(val); err == nil {
412-
return oid
411+
if strings.HasPrefix(v, "\"") && strings.HasSuffix(v, "\"") {
412+
v = v[1 : len(v)-1]
413413
}
414-
}
415-
if strings.ToLower(val) == "true" || strings.ToLower(val) == "false" {
416-
return strings.ToLower(val) == "true"
414+
if field == "_id" && len(v) == 24 {
415+
if oid, err := primitive.ObjectIDFromHex(v); err == nil {
416+
return oid
417+
}
418+
}
419+
if strings.ToLower(v) == "true" || strings.ToLower(v) == "false" {
420+
return strings.ToLower(v) == "true"
421+
}
422+
423+
val = v
417424
}
418425
if timeVal, err := typeutils.ReformatDate(val); err == nil {
419426
return timeVal

0 commit comments

Comments
 (0)