V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
bankroft
V2EX  ›  Go 编程语言

求问:如何修改 bson.Raw

  •  
  •   bankroft · 2020-04-22 11:34:24 +08:00 · 1275 次点击
    这是一个创建于 1464 天前的主题,其中的信息可能已经有所发展或是发生改变。
    testM := bson.M{
    		"dict": "v1",
    }
    var raw bson.Raw
    tmp, _ := bson.Marshal(testM)
    bson.Unmarshal(tmp, &raw)
    

    对 raw 进行修改,新增 key: document 为

    bsonM{"dict":"v1", "key": document}
    

    或者修改为

    bson.M{"dict": "v2"}
    

    又或者删除 key 为

    bsonM{}
    

    我没找到相关的文章,godoc 也看着没头绪

    求问有啥办法可以做到对 bson.Raw 的增删改

    1 条回复    2020-04-22 13:55:49 +08:00
    index90
        1
    index90  
       2020-04-22 13:55:49 +08:00   ❤️ 1
    最近在封装 mongodb 相关的库,这个包 go.mongodb.org/[email protected]/x/bsonx/bsoncore/document.go 里有你想要的东西
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3287 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 13:03 · PVG 21:03 · LAX 06:03 · JFK 09:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.