Skip to content

Updater 序列化错误,导致数据无法更新正确 #113

@shuqingzai

Description

@shuqingzai

在提交之前请先查找 已有 issues,避免重复上报。| Before submitting, please search for existing issues to avoid duplicate reports.

并且确保自己已经 | Also, ensure that you have:

  • 阅读过文档 | Read the documentation
  • 阅读过注释 | Reviewed the comments
  • 阅读过例子 | Looked at the examples

您使用的 mongox 版本 | The version of mongox you are using

github.com/chenmingyong0423/go-mongox/v2

您遇到的问题 | The issue you encountered.

  1. 在更新操作时,会进行一次预先序列化为 bson.M ,这是出于什么考虑?
    updates := bsonx.ToBsonM(u.updates)
    if len(updates) != 0 {
    u.updates = updates
    }
    1. 它引发了如下问题
      1. 使用默认的编解码器,无法对自定义类型进行编解码,导致数据无法正确序列化

        go-mongox/bsonx/bsonx.go

        Lines 78 to 91 in 19e6f49

        func dToM(d bson.D) bson.M {
        marshal, err := bson.Marshal(d)
        if err != nil {
        return nil
        }
        var m bson.M
        decoder := bson.NewDecoder(bson.NewDocumentReader(bytes.NewReader(marshal)))
        decoder.DefaultDocumentM()
        err = decoder.Decode(&m)
        if err != nil {
        return nil
        }
        return m
        }
      2. 多一次的序列化对于追求性能的场景,会有所影响
    2. 即使不进行预先序列化,它可以正常运行
  2. 如下,两个字段应该是有效的时间结构体,需要使用自定义的编解码器才能正确序列化,但是由于预先序列化,导致它变成不可用的数据
Image Image Image

正确的如下:

Image

复现步骤 | Steps to reproduce> 请提供简单的复现代码 | Please provide simple code to reproduce the issue.

错误日志或者截图 | Error logs or Screenshots

你排查的结果,或者你觉得可行的修复方案 | Your Findings or Possible Solutions

可选。我们希望你能够尽量先排查问题,帮助我们减轻维护负担。这对于你个人能力提升同样是有帮助的。| Optional. We hope you can try to troubleshoot the issue first, helping us to reduce our maintenance burden. This is also beneficial for your personal skill development

您期望的结果 | Expected Outcome

你设置的的 Go 环境 | Your Go Environment Setting

上传 go env 的结果 | Upload the result of go env

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions