小编Gau*_*arg的帖子

为什么我不能使用golang的mgo库找到ID?

我在golang中使用mgo库进行mongo操作,这是我的代码:

session.SetMode(mgo.Monotonic, true)
coll := session.DB("aaaw_web").C("cron_emails")
var result Result
fmt.Printf("%v", message.ID)
err = coll.FindId(bson.ObjectId(message.ID)).One(&result)
fmt.Printf("%v", result)
fmt.Println(err)
Run Code Online (Sandbox Code Playgroud)

我得到这个输出:

595f2c1a6edcba0619073263
{ObjectIdHex("") 0   0  0    0 {         0    false 0    } 0 0 0  0 0 0 0}
ObjectIDs must be exactly 12 bytes long (got 24)
not found
Run Code Online (Sandbox Code Playgroud)

但我查了一下,文件存在于mongo中,但是到这里没有结果,任何想法我错过了什么...

go mgo

7
推荐指数
1
解决办法
2384
查看次数

如何在 golang 中打印未编组的数据?

我正在 golang 中从 Raabbitmq 读取 json 并将该 json 映射到接口中

我的结构看起来像这样,并且

type Documents struct {
    user_id    string
    partner_id []string
    last_login int
}
Run Code Online (Sandbox Code Playgroud)

我正在上面的结构中映射传入的 json,但出于 debugginf 的目的,我想查看接口数组,我如何打印映射的数据数组(在我的例子中是主体)

        var body []Documents
        json.Unmarshal(d.Body, &body)

        log.Printf("Received a message: %s", body)
Run Code Online (Sandbox Code Playgroud)

我需要输入其他标识符来代替 %s 吗?

json go glide-golang

2
推荐指数
1
解决办法
2507
查看次数

标签 统计

go ×2

glide-golang ×1

json ×1

mgo ×1