Documentation ¶
Index ¶
- Constants
- type Link
- func (l Link) Collection(database, collection string) (*mongo.Collection, error)
- func (l *Link) CountDocs(database, collection string, filter interface{}) (int64, error)
- func (l *Link) DeleteMany(database, collection string, filter interface{}) (int64, error)
- func (l *Link) DeleteOne(database, collection string, filter interface{}) (int64, error)
- func (l *Link) Disconnect()
- func (l *Link) Find(database, collection string, filter interface{}, dest interface{}) error
- func (l *Link) FindOne(database, collection string, filter interface{}, dest interface{}) error
- func (l *Link) InsertMany(database, collection string, document []interface{}) ([]string, error)
- func (l *Link) InsertOne(database, collection string, document interface{}) (string, error)
- func (l *Link) UpdateMany(database, collection string, filter, update interface{}) (int64, error)
- func (l *Link) UpdateOne(database, collection string, filter, update interface{}) (int64, error)
- type Options
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 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link is a concentrator wrapper for mongodb client
func New ¶
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 ¶
func (l Link) Collection(database, collection string) (*mongo.Collection, error)
Collection returns a collection from the target database
func (*Link) CountDocs ¶
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 ¶
DeleteMany wraps the mongo.Database.Collection.DeleteMany() method It returns the number of affected records and an error
func (*Link) DeleteOne ¶
DeleteOne wraps the mongo.Database.Collection.DeleteOne() method It returns the number of affected records and an error
func (*Link) Disconnect ¶
func (l *Link) Disconnect()
Disconnect closes the client connection with database
func (*Link) Find ¶
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 ¶
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 ¶
InsertMany wraps the mongo.Database.Collection.InsertMany() method It returns an array with generated ObjectIDs and an error
func (*Link) InsertOne ¶
InsertOne wraps the mongo.Database.Collection.InsertOne() method It returns the generated ObjectId and an error
func (*Link) UpdateMany ¶
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 ¶
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 ¶
type Options struct {
// contains filtered or unexported fields
}
Options contains all necessary parameters to connect and mantain database client
func OptionsNew ¶
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