Documentation ¶
Index ¶
- Variables
- func AllItems(collection *mongo.Collection) ([]bson.M, error)
- func CheckConnection(client *mongo.Client) bool
- func CreateEntries(collection *mongo.Collection, docs []interface{}) ([]interface{}, error)
- func CreateEntry(collection *mongo.Collection, doc bson.D) (interface{}, error)
- func FindManyItems(collection *mongo.Collection, filter interface{}) ([]bson.M, error)
- func RemoveMany(collection *mongo.Collection, filter interface{}) (*mongo.DeleteResult, error)
- func RemoveOne(collection *mongo.Collection, filter interface{}) (*mongo.DeleteResult, error)
- func SingleItem(collection *mongo.Collection, filter bson.D) (bson.D, error)
- type DBCreate
- type DBInteract
Constants ¶
This section is empty.
Variables ¶
var ( Database *mongo.Database Client *mongo.Client Collection *mongo.Collection )
declare variables
Functions ¶
func AllItems ¶
func AllItems(collection *mongo.Collection) ([]bson.M, error)
AllItems retrieves all items in a collection
func CheckConnection ¶
CheckConnection checks server connectivity using the Ping method Calling Connect does not block for server discovery.
func CreateEntries ¶
func CreateEntries(collection *mongo.Collection, docs []interface{}) ([]interface{}, error)
CreateEntries adds records(docs) to the database(dbs) into Collection(collection) returns the id's created and possible error
func CreateEntry ¶
func CreateEntry(collection *mongo.Collection, doc bson.D) (interface{}, error)
CreateEntry adds a record(doc) to the database(dbs) into Collection(collection)
func FindManyItems ¶
func FindManyItems(collection *mongo.Collection, filter interface{}) ([]bson.M, error)
FingManyItems retrieves more than one items in a collection with filter in the form of bson.D, bson.M, bson.A
func RemoveMany ¶
func RemoveMany(collection *mongo.Collection, filter interface{}) (*mongo.DeleteResult, error)
RemoveMany deletes multiple record from a collection filter is in the form bson.D, bson.M, bson.A
func RemoveOne ¶
func RemoveOne(collection *mongo.Collection, filter interface{}) (*mongo.DeleteResult, error)
RemoveOne deletes a record from a collection
func SingleItem ¶
SingleItem returns a single item from the database For methods that return a single item, a SingleResult, which works like a *sql.Row: filter := bson.D{{"name", "pi"}}
Types ¶
type DBCreate ¶
type DBCreate interface { CreateEntry(dbs *mongo.Database, collection string, doc bson.D) (interface{}, error) CreateEntries(dbs *mongo.Database, collection string, docs []interface{}) ([]interface{}, error) }
create an interface for abstracting document creation
type DBInteract ¶
type DBInteract interface { SingleItem(collection *mongo.Collection, filter bson.D) (bson.D, error) AllItems(collection *mongo.Collection) ([]bson.M, error) FindManyItems(collection *mongo.Collection, filter interface{}) ([]bson.M, error) RemoveOne(collection *mongo.Collection, filter interface{}) (*mongo.DeleteResult, error) RemoveMany(collection *mongo.Collection, filter interface{}) (*mongo.DeleteResult, error) }
create an interaction interface for abstraction