Model:
type Vehicle struct {
Id bson.ObjectId `bson:"_vid,omitempty"`
Brand string
Category string
CategorySubject string
MakeYear string
RegistrationNumber string
Model string
Price string
}
func (this *Vehicle)AddToDB(emailId1 string) {
sess, db := GetDatabase()
defer sess.Close()
c := db.C("user")
//newId :=Vehicle{}
/*colQuerier := bson.M{"email": person.Email}
change := bson.M{"$set": bson.M{"profile" : imgName}}
err = c.Update(colQuerier, change)*/
colQuerier := bson.M{"email": emailId1}
change := bson.M{"$push": bson.M{"myvehicle" : &this}}
err := c.Update(colQuerier, change)
if err != nil {
fmt.Println("not inserted")
}
}
The value of Id
of Vehicle is empty when it's pushed into myvehicle
field.
How do I set a value for the nested Vehicle's id ?