Documentation ¶
Overview ¶
Package db provides helper functions that make interfacing with the MongoDB Go driver library easier
Index ¶
- Constants
- Variables
- type CnctConnection
- func (db CnctConnection) DeleteMany(filter bson.D) error
- func (db CnctConnection) DeleteOne(filter bson.D) error
- func (db CnctConnection) Drop() error
- func (db CnctConnection) FindMany(filter bson.D, res *[]interface{}) error
- func (db CnctConnection) FindOne(filter bson.D, res interface{}) error
- func (db CnctConnection) InsertMany(new []interface{}) (interface{}, error)
- func (db CnctConnection) InsertOne(new interface{}) (interface{}, error)
- func (db CnctConnection) UpdateMany(filter, update bson.D) (int64, int64, error)
- func (db CnctConnection) UpdateOne(filter, update bson.D) (int64, int64, error)
Constants ¶
const OperationTimeOut = 5
OperationTimeOut is the time limit for context before cancelling
Variables ¶
var Client *mongo.Client
Client holds the reference to the underlying MongoDB client
var Ctx context.Context
Ctx holds the current context
Functions ¶
This section is empty.
Types ¶
type CnctConnection ¶
type CnctConnection struct {
Collection *mongo.Collection
}
CnctConnection is the wrapper for Mongo Collection
func New ¶
func New(uri, db, cnct string) (c CnctConnection)
New creates a new connection to Mongo Collection
func (CnctConnection) DeleteMany ¶
func (db CnctConnection) DeleteMany(filter bson.D) error
DeleteMany deletes all documents that match the bson.D filter
func (CnctConnection) DeleteOne ¶
func (db CnctConnection) DeleteOne(filter bson.D) error
DeleteOne deletes single document that match the bson.D filter
func (CnctConnection) Drop ¶
func (db CnctConnection) Drop() error
Drop drops the current CnctConnection (collection)
func (CnctConnection) FindMany ¶
func (db CnctConnection) FindMany(filter bson.D, res *[]interface{}) error
FindMany iterates cursor of all docs matching filter and fills res with unmarshalled documents.
func (CnctConnection) FindOne ¶
func (db CnctConnection) FindOne(filter bson.D, res interface{}) error
FindOne finds first document that satisfies filter and fills res with the unmarshalled document.
func (CnctConnection) InsertMany ¶
func (db CnctConnection) InsertMany(new []interface{}) (interface{}, error)
InsertMany takes a slice of structs, inserts them into the database, and returns list of inserted IDs
func (CnctConnection) InsertOne ¶
func (db CnctConnection) InsertOne(new interface{}) (interface{}, error)
InsertOne inserts a single struct as a document into the database and returns its ID. Returns inserted ID
func (CnctConnection) UpdateMany ¶
UpdateMany updates all documents matching the filter by applying the update query on it. Returns number of documents matched and modified.