@Preston_Vasquez
Thank you for your reply, I added a case for type Null like below but still got 0 instead nil
Is there another way to get nil and not use bson.RawValue ?
switch t {
case bson.TypeInt32:
intValue, _, ok := bsoncore.ReadInt32(value)
if !ok {
return fmt.Errorf("failed to read BSON int32")
}
*i = DBInt64(intValue)
case bson.TypeInt64:
intValue, _, ok := bsoncore.ReadInt64(value)
if !ok {
return fmt.Errorf("failed to read BSON int64")
}
*i = DBInt64(intValue)
case bson.TypeString:
s, _, ok := bsoncore.ReadString(value)
if !ok {
return fmt.Errorf("failed to read BSON string")
}
if utils.IsEmptyString(&s) {
*i = DBInt64(0)
break
}
ret, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return fmt.Errorf("failed to convert BSON string to int64: %s", err.Error())
}
*i = DBInt64(ret)
case bson.TypeDouble:
floatValue, _, ok := bsoncore.ReadDouble(value)
if !ok {
return fmt.Errorf("failed to read BSON float64")
}
*i = DBInt64(floatValue)
case bson.TypeNull:
return nil
default:
*i = DBInt64(0)
}
return nil
}