如何在Golang / mgo中的Mongodb中插入子文档?

Say for example I had the following struct:

type Article struct {
    Title string `form"title" json:"title"`
    Categories []*Category 
}

How would I go about adding a new category?

Sorted it using:

change := mgo.Change{
    Update: bson.M{"$push": bson.M{"categories": cat}},
}

_, err := repo.collection.FindId(bson.ObjectIdHex(article)).Apply(change, nil)

if err != nil {
    panic(err)
}

Update the Article struct as :

type Article struct {
   ArticleId  string      `bson:"_id"`
   Title      string      `form"title" json:"title,omitempty"`
   Categories []Category  `json:"category,omitempty"`
}

Your Query accordingly:

data := model.Category{
            CategoryId :      "yourText",
            Product    :      "productName,
             ...
        }

selector := bson.M{"_id": "provideTheTitle"}
changes := bson.M{"$push": bson.M{"category": bson.M{"$each": []model.Category{data}}}}
err = c.Update(selector, changes)

It would be great if you can share your Category struct and include an field _id in your Article struct.