开发者社区 问答 正文

mgo插入_id,如何做?

我用的是labix.org 的 mgo驱动,
给struct加一个 _id 变量 往mongoDB里插入 _id 索引,但是总是无效。
这个怎么回事??

展开
收起
落地花开啦 2016-02-07 11:32:25 2793 分享 版权
1 条回答
写回答
取消 提交回答
  • 喜欢技术,喜欢努力的人

    尝试以下代码
    `type Person struct {
    PersonalId string bson:"_id"
    Name string bson:"name"
    Phone string bson:"phone"
    }
    c := session.DB("test").C("persons")
    err := c.Insert(&Person{"230121197807252341", "Andrew Liu","13000132488"} `

    2019-07-17 18:38:57
    赞同 展开评论