这是我的结构体:
type Article struct { Id bson.ObjectId `json:"id" bson:"_id"` Title string `json:"title"` Author string `json:"author"` Date string `json:"date"` Tags string `json:"tags"` Content string `json:"content"` Status string `json:"status"` }
这是我获取 mongodb 中数据的函数:
func AllArticles() []Article {
articles := []Article{}
err := c_articles.Find(bson.M{}).All(&articles)
if err != nil {
panic(err)
}
fmt.Println(articles)
return articles
}
这是打印结果:
[{ObjectIdHex("") Hello1 DYZ 2013-11-10 abc This is another content. published} {ObjectIdHex("") Hello2 DYZ 2013-11-14 abc This is the content. published} {ObjectIdHex("") Hello3 DYZ 2013-11-15 abc This is the content haven't been published. draft}]
可以看到,对应_id
的值是ObjectIdHex("")
,但是在数据库中的数据是这样的:
{ "_id" : ObjectId("5281b83afbb7f35cb62d0834"), "title" : "Hello1", "author" : "DYZ", "date" : "2013-11-10", "tags" : "abc", "content" : "This is another content.", "status" : "published" }
即使我把筛选条件变成:
err := c_articles.Find(bson.M{"_id": bson.ObjectIdHex("5281b83afbb7f35cb62d0834")}).All(&articles)
打印出来的数据仍然是上面那样,没有值。这是为什么?
Id bson.ObjectId json:"id" bson:"_id"
json和bson之间的空格是否用了tab?
在so中找到原因了
windows和unix仓库提交网址不一致
stockoverflow上的解释
docker login --username=youruser --password=yourpassword --email=youremail https://index.docker.io/v1/
具体可以看上面柳月给的网址或者:https://github.com/docker/hub-feedback/issues/473