// unbindUnit unbinds a unit from all service instances that are bound to the // app. It is used by RemoveUnit and RemoveUnits methods. func (app *App) unbindUnit(unit provision.AppUnit) error { conn, err := db.Conn() if err != nil { return err } defer conn.Close() var instances []service.ServiceInstance q := bson.M{"apps": bson.M{"$in": []string{app.Name}}} err = conn.ServiceInstances().Find(q).All(&instances) if err != nil { return err } for _, instance := range instances { err = instance.UnbindUnit(unit) if err != nil { log.Printf("Error unbinding the unit %s with the service instance %s.", unit.GetIp(), instance.Name) } } return nil }