Documentation ¶
Overview ¶
The mongo package is a very simple wrapper around the github.com/globalsign/mgo/bson package. It's purpose is to allow you to do CRUD operations with very little code. It's not exhaustive and not meant to do everything for you.
Index ¶
- Variables
- func Count(i interface{}) (int, error)
- func Delete(i interface{}) error
- func Find(i interface{}, q bson.M, sortFields ...string) error
- func FindById(i interface{}, id string) error
- func GetColl(session *mgo.Session, coll string) *mgo.Collection
- func GetSession() (*mgo.Session, error)
- func Insert(records ...interface{}) error
- func SetServers(servers, db string) error
- func Update(i interface{}) error
- type Id
Constants ¶
This section is empty.
Variables ¶
var (
NoPtr = errors.New("You must pass in a pointer")
)
Functions ¶
func Delete ¶
func Delete(i interface{}) error
Deletes a record. Uses the Id to identify the record to delete. Must pass in a pointer to a struct.
func Find ¶
Find one or more records. If a single struct is passed in we'll return one record. If a slice is passed in all records will be returned. Must pass in a pointer to a struct or slice of structs. Use sortFields to sort the results. See http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order for more info.
func GetColl ¶
func GetColl(session *mgo.Session, coll string) *mgo.Collection
We pass in the session because that is a clone of the original and the caller will need to close it when finished.
func GetSession ¶
Returns a Mongo session. You must call Session.Close() when you're done.