साथ MgO का उपयोग कर "_ id" मान यह मेरा struct परिभाषा है:प्राप्त नहीं कर सकते golang
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"`
}
इस विधि मैं डेटाबेस से अपने डेटा मिलता है:
func AllArticles() []Article {
articles := []Article{}
err := c_articles.Find(bson.M{}).All(&articles)
if err != nil {
panic(err)
}
return articles
}
इस वस्तु में से एक टुकड़ा है
{ "_id" : ObjectId("5281b83afbb7f35cb62d0834"),
"title" : "Hello1",
"author" : "DYZ",
"date" : "2013-11-10",
"tags" : "abc",
"content" : "This is another content.",
"status" : "published" }
यह मुद्रित परिणाम है:: डेटाबेस में संग्रहीत
[{ObjectIdHex("") Hello1 DYZ 2013-11-10 abc This is another content. published} {ObjectIdHex("") Hello2 DYZ 2013-11-14 abc This is the content. published}]
ऐसा लगता है कि मुझे _id
फ़ील्ड का वास्तविक मूल्य नहीं मिल सकता है, यह हमेशा ""
है। समस्या क्या है?
मैंने सोचा कि '_id' प्रत्येक ऑब्जेक्ट का डिफ़ॉल्ट फ़ील्ड है, है ना? – dyzdyz010
शायद आप अपने लेख गलत डाल रहे हैं। – thwd
@ dyzdyz010 http://goo.gl/M1VsXt –