Der Wert "_id" kann nicht mit mgo mit golang abgerufen werden

Dies ist mein struct-definition:

type Article struct {
    Id      bson.ObjectId `json:"id"        bson:"_id,omitempty"`
    Title   string        `json:"title"`
    Author  string        `json:"author"`
    Date    string        `json:"date"`
    Tags    string        `json:"tags"`
    Content string        `json:"content"`
    Status  string        `json:"status"`
}

Dies ist die Methode, die ich meine Daten aus der Datenbank:

func AllArticles() []Article {
    articles := []Article{}
    err := c_articles.Find(bson.M{}).All(&articles)
    if err != nil {
        panic(err)
    }

    return articles
}

Dies ist ein Stück von Objekt in der Datenbank gespeichert:

{ "_id" : ObjectId( "5281b83afbb7f35cb62d0834" ),
  "title" : "Hello1",
  "author" : "DYZ",
  "date" : "2013-11-10",
  "tags" : "abc",
  "content" : "This is another content.",
  "status" : "published" }

Dies ist das gedruckte Ergebnis:

[{ObjectIdHex("") Hello1 DYZ 2013-11-10 abc This is another content. published}     {ObjectIdHex("") Hello2 DYZ 2013-11-14 abc This is the content. published}]

Es scheint, dass ich kann nicht den realen Wert der _id Feld, es ist immer "". Was ist das problem?

InformationsquelleAutor der Frage dyzdyz010 | 2013-11-26

Schreibe einen Kommentar