mongoconnect

package module
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: MIT Imports: 8 Imported by: 0

README

mongoconnect

Golang Package to connect to MongoDB and do CRUD on a database

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 added in v1.0.0

func AllItems(dbs *mongo.Database, colName string) ([]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 added in v1.5.0

func CreateEntries(dbs *mongo.Database, collection string, 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(dbs *mongo.Database, collection string, doc bson.D) (interface{}, error)

CreateEntry adds a record(doc) to the database(dbs) into Collection(collection)

func RemoveMany added in v1.5.0

func RemoveMany(collection *mongo.Collection, filter interface{}) (*mongo.DeleteResult, error)

RemoveMany deletes multiple record from a collection

func RemoveOne added in v1.5.0

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

This section is empty.

Jump to

Keyboard shortcuts

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