func (c Country) Update() error { session, database := common.Session() defer common.Close(session) country := database.C(collection) return country.Update(bson.M{"_id": c.Id}, c) }
func (c Country) Create() error { session, database := common.Session() defer common.Close(session) country := database.C(collection) return country.Insert(&c) }
func All() ([]Country, error) { session, database := common.Session() defer common.Close(session) country := database.C(collection) result := []Country{} if err := country.Find(bson.M{}).All(&result); err != nil { return nil, err } return result, nil }
func FindById(id string) (Country, error) { session, database := common.Session() defer common.Close(session) country := database.C(collection) result := Country{} if bson.IsObjectIdHex(id) { err := country.FindId(bson.ObjectIdHex(id)).One(&result) return result, err } else { return result, errors.New(fmt.Sprintf("Invalid Object Id: %s", id)) } }