func (s *TaskDAOMongo) getAllTasksByQuery(query interface{}, start, end int) ([]model.Task, error) {
	session := s.session.Copy()
	defer session.Close()
	c := session.DB("").C(collection)
	hasPaging := start > NoPaging && end > NoPaging && end >= start
	var err error
	var tasks []model.Task
	if hasPaging {
		err = c.Find(query).Skip(start).Limit(end - start + 1).All(&tasks)
	} else {
		err = c.Find(query).All(&tasks)
	}
	if err != nil && err == mgo.ErrNotFound {
		return nil, ErrNotFound
	}
	return tasks, err
}
getAllTasksByQuery returns tasks by query and paging capability
package dao
import (
	"github.com/Sfeir/golang-200/model"
	"github.com/satori/go.uuid"
	logger "github.com/sirupsen/logrus"
	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)
var _ TaskDAO = (*TaskDAOMongo)(nil)
const (
	collection = "tasks"
	index      = "id"
)
type TaskDAOMongo struct {
	session *mgo.Session
}
func NewTaskDAOMongo(session *mgo.Session) TaskDAO {
	err := session.DB("").C(collection).EnsureIndex(mgo.Index{
		Key:        []string{index},
		Unique:     true,
		DropDups:   true,
		Background: true,
		Sparse:     true,
	})
	if err != nil {
		logger.WithField("error", err).Warn("mongo db connection")
	}
	return &TaskDAOMongo{
		session: session,
	}
}
func (s *TaskDAOMongo) GetByID(ID string) (*model.Task, error) {
	if _, err := uuid.FromString(ID); err != nil {
		return nil, ErrInvalidUUID
	}
	session := s.session.Copy()
	defer session.Close()
	task := model.Task{}
	c := session.DB("").C(collection)
	err := c.Find(bson.M{"id": ID}).One(&task)
	if err != nil && err == mgo.ErrNotFound {
		return nil, ErrNotFound
	}
	return &task, err
}