mongoconnect

package module
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func CheckConnection(client *mongo.Client) bool

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

func SingleItem(collection *mongo.Collection, filter bson.D) (bson.D, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL