// RepoCreateFamily creates a family in the mongo collection func RepoCreateFamily(family *models.Family) (id bson.ObjectId, err error) { mongoSession, err := mgo.Dial(util.Configuration.MongoURL) if err != nil { log.Printf("MongoDB connection failed, with address '%s'.", util.Configuration.MongoURL) } defer mongoSession.Close() c := mongoSession.DB(util.Configuration.MongoDbName).C(familiesCollection) myID := util.GetNewID() family.FamilyID = myID err = c.Insert(family) if mgo.IsDup(err) { // retry insert with new id RepoCreateFamily(family) } else if err != nil { log.Printf("Mongo insert to %s/%s returned '%s'", util.Configuration.MongoDbName, familiesCollection, err.Error()) } return myID, err }