Hi,
This code works for me.
You need to pass referance instead of actual variable.
//here mongo is my package where function MongoConnect() creates a globle
session and returns clone of session.
func addTempCategory(category MainCategory) {
mongoSession = mongo.MongoConnect()
defer mongoSession.Close()
c := mongo.MongoSession.DB("testDB").C("testCategories")
err := c.Insert(&category)
if err != nil {
log.Fatal(err)
}
}
And struct for category
type MainCategory struct {
Category string `bson:"category" json:"category"`
CategoryID string `bson:"categoryId" json:"categoryId"`
CategoryName string `bson:"categoryName" json:"categoryName"`
HaveAttributes int `bson:"haveAttributes" json:"haveAttributes"`
HaveSubCats int `bson:"haveSubCats" json:"haveSubCats"`
ImageIcon string `bson:"imageIcon" json:"imageIcon"`
}
On Wednesday, January 9, 2019 at 4:29:39 PM UTC+5:30, [email protected]
wrote:
>
> My code:
> session.SetMode(mgo.Monotonic, true)
> d:= session.DB("api").C("api")
> doc := Data{
> Name: title,
> Away: band,
> }
> err = d.Insert(doc)
> json to expect
> [
> {
> "contentData": "",
> "historyData": " ",
>
> },
> {
> },
> ]
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.