func (h mongoHandle) GetFileByFilename(filename string) (thisFile types.File, err error) {
	err = h.Gfs.Find(bson.M{"filename": strings.ToLower(filename)}).One(&thisFile)
	if err != nil {
		return thisFile, err
	}
	return thisFile, nil
}
Get one file back, by searching by file name
package mongo
import (
	"encoding/json"
	"strings"
	"github.com/vbatts/imgsrv/dbutil"
	"github.com/vbatts/imgsrv/types"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
)
func init() {
	dbutil.Handles["mongo"] = &mongoHandle{}
}
const defaultDbName = "filesrv"
type dbConfig struct {
	Seed   string  
	User   string  
	Pass   string  
	DbName string  
}
type mongoHandle struct {
	config  dbConfig
	Session *mgo.Session
	FileDb  *mgo.Database
	Gfs     *mgo.GridFS
}
func (h *mongoHandle) Init(config []byte, err error) error {
	if err != nil {
		return err
	}
	h.config = dbConfig{}
	if err := json.Unmarshal(config, &h.config); err != nil {
		return err
	}
	h.Session, err = mgo.Dial(h.config.Seed)
	if err != nil {
		return err
	}
	if len(h.config.DbName) > 0 {
		h.FileDb = h.Session.DB(h.config.DbName)
	} else {
		h.FileDb = h.Session.DB(defaultDbName)
	}
	if len(h.config.User) > 0 && len(h.config.Pass) > 0 {
		err = h.FileDb.Login(h.config.User, h.config.Pass)
		if err != nil {
			return err
		}
	}
	h.Gfs = h.FileDb.GridFS("fs")
	return nil
}
func (h mongoHandle) Close() error {
	h.Session.Close()
	return nil
}
func (h mongoHandle) Open(filename string) (file dbutil.File, err error) {
	return h.Gfs.Open(strings.ToLower(filename))
}
func (h mongoHandle) Create(filename string) (file dbutil.File, err error) {
	return h.Gfs.Create(strings.ToLower(filename))
}
func (h mongoHandle) Remove(filename string) (err error) {
	return h.Gfs.Remove(strings.ToLower(filename))
}
func (h mongoHandle) FindFilesByMd5(md5 string) (files []types.File, err error) {
	err = h.Gfs.Find(bson.M{"md5": md5}).Sort("-metadata.timestamp").All(&files)
	return files, err
}
func (h mongoHandle) FindFilesByName(filename string) (files []types.File, err error) {
	err = h.Gfs.Find(bson.M{"filename": filename}).Sort("-metadata.timestamp").All(&files)
	return files, err
}
func (h mongoHandle) FindFilesByPatt(filenamePat string) (files []types.File, err error) {
	err = h.Gfs.Find(bson.M{"filename": bson.M{"$regex": filenamePat, "$options": "i"}}).Sort("-metadata.timestamp").All(&files)
	return files, err
}
func (h mongoHandle) FindFilesByKeyword(keyword string) (files []types.File, err error) {
	err = h.Gfs.Find(bson.M{"metadata.keywords": strings.ToLower(keyword)}).Sort("-metadata.timestamp").All(&files)
	return files, err
}
func (h mongoHandle) GetFiles(limit int) (files []types.File, err error) {
	if limit == -1 {
		err = h.Gfs.Find(nil).Sort("-metadata.timestamp").All(&files)
	} else {
		err = h.Gfs.Find(nil).Sort("-metadata.timestamp").Limit(limit).All(&files)
	}
	return files, err
}
func (h mongoHandle) CountFiles(filename string) (count int, err error) {
	query := h.Gfs.Find(bson.M{"filename": strings.ToLower(filename)})
	return query.Count()
}