mongohelper: github.com/miguelpragier/mongohelper Index | Files

package mongohelper

import "github.com/miguelpragier/mongohelper"

Index

Package Files

collection.go connect.go countdocs.go deletemany.go deleteone.go disconnect.go find.go findone.go insertmany.go insertone.go link.go linkcheck.go mongohelper.go options.go updatemany.go updateone.go

Constants

const (
    // SecondsBetweenAttemptsMin When retrying connection, minimum time betwwen attempts
    SecondsBetweenAttemptsMin uint = 5
    // ConnectionTimeoutSecondsDefault limits the time waiting from a connection request
    ConnectionTimeoutSecondsDefault uint = 30
    // ConnectionTimeoutSecondsMin limits the minimum time waiting from a connection request
    ConnectionTimeoutSecondsMin uint = 3
    // ExecutionTimeoutSecondsDefault limits the time waiting from an execution request
    ExecutionTimeoutSecondsDefault uint = 10
    // ExecutionTimeoutSecondsMin limits the minimum time waiting from an execution request
    ExecutionTimeoutSecondsMin uint = 1
)
type Link struct {
    // contains filtered or unexported fields
}

Link is a concentrator wrapper for mongodb client

func New Uses

func New(opts *Options) (*Link, error)

New returns an instance of mongohelper, ugins given options It the connection conditions are ok, it comes alerady connected and tested with .Ping() You may prefer to create the options with .OptionsNew() function

func (Link) Collection Uses

func (l Link) Collection(database, collection string) (*mongo.Collection, error)

Collection returns a collection from the target database

func (*Link) CountDocs Uses

func (l *Link) CountDocs(database, collection string, filter interface{}) (int64, error)

CountDocs wraps the mongo.Database.Collection.CountDocuments() method It returns the number of documents in the collection and an error

The filter parameter must be a document and can be used to select which documents contribute to the count. It cannot be nil. An empty document (e.g. bson.D{}) should be used to count all documents in the collection. This will result in a full collection scan.

func (*Link) DeleteMany Uses

func (l *Link) DeleteMany(database, collection string, filter interface{}) (int64, error)

DeleteMany wraps the mongo.Database.Collection.DeleteMany() method It returns the number of affected records and an error

func (*Link) DeleteOne Uses

func (l *Link) DeleteOne(database, collection string, filter interface{}) (int64, error)

DeleteOne wraps the mongo.Database.Collection.DeleteOne() method It returns the number of affected records and an error

func (*Link) Disconnect Uses

func (l *Link) Disconnect()

Disconnect closes the client connection with database

func (*Link) Find Uses

func (l *Link) Find(database, collection string, filter interface{}, dest interface{}) error

Find cs wraps the mongo.Database.Collection.Find() method It returns a Cursor over the matching documents in the collection.

The filter parameter must be a document containing query operators and can be used to select which documents are included in the result. An empty document (e.g. bson.D{}) should be used to include all documents.

func (*Link) FindOne Uses

func (l *Link) FindOne(database, collection string, filter interface{}, dest interface{}) error

FindOne wraps the mongo.Database.Collection.FindOne() method It returns a SingleResult for one document in the collection.

The filter parameter must be a document containing query operators and can be used to select the document to be returned. If the filter does not match any documents, a SingleResult with an error set to ErrNoDocuments will be returned. If the filter matches multiple documents, one will be selected from the matched set.

func (*Link) InsertMany Uses

func (l *Link) InsertMany(database, collection string, document []interface{}) ([]string, error)

InsertMany wraps the mongo.Database.Collection.InsertMany() method It returns an array with generated ObjectIDs and an error

func (*Link) InsertOne Uses

func (l *Link) InsertOne(database, collection string, document interface{}) (string, error)

InsertOne wraps the mongo.Database.Collection.InsertOne() method It returns the generated ObjectId and an error

func (*Link) UpdateMany Uses

func (l *Link) UpdateMany(database, collection string, filter, update interface{}) (int64, error)

UpdateMany wraps the mongo.Database.Collection.UpdateMany() method It returns the number of matched records and an error The filter parameter must be a document containing query operators and can be used to select the documents to be updated. It cannot be nil. If the filter does not match any documents, the operation will succeed and an UpdateResult with a MatchedCount of 0 will be returned.

The update parameter must be a document containing update operators (https://docs.mongodb.com/manual/reference/operator/update/) and can be used to specify the modifications to be made to the selected documents. It cannot be nil or empty.

func (*Link) UpdateOne Uses

func (l *Link) UpdateOne(database, collection string, filter, update interface{}) (int64, error)

UpdateOne wraps the mongo.Database.Collection.UpdateOne() method It returns the number of matched records and an error The filter parameter must be a document containing query operators and can be used to select the document to be updated. It cannot be nil. If the filter does not match any documents, the operation will succeed and an UpdateResult with a MatchedCount of 0 will be returned. If the filter matches multiple documents, one will be selected from the matched set and MatchedCount will equal 1.

The update parameter must be a document containing update operators (https://docs.mongodb.com/manual/reference/operator/update/) and can be used to specify the modifications to be made to the selected document. It cannot be nil or empty.

type Options Uses

type Options struct {
    // contains filtered or unexported fields
}

Options contains all necessary parameters to connect and mantain database client

func OptionsNew Uses

func OptionsNew(appName, connectionString string, connectTimeoutInSeconds, execTimeoutInSeconds, reconnectTimeInSeconds, reconnecAttemptsLimit, reconnectAttemptsLimitMinutes uint, insistOnFail, logMessages bool) *Options

OptionsNew returns a pointer to mongohelper.Options instance. Why a pointer? In this case is because you can send nil instead, and the engine provides default values. connString, a well-formed URI for mongodb. Attention: is mandatory connectTimeoutInSeconds is quite obvious reconnectTimeInSeconds Seconds btween each connection attempt reconnecAttemptsLimit maximum number of (re)connection attempts or 0 for infinite reconnectAttemptsLimitMinutes maximum time ( in minutes ) trying to (re)connect or 0 for infinite insistOnFail If can't connect on first attempt, if should retry logMessages if true allow the engine to print out log messages to stdout

Package mongohelper imports 10 packages (graph). Updated 2020-06-13. Refresh now. Tools for package owners.