Documentation ¶
Overview ¶
Database connection for mongo db. The database is accessable by using the DB variable. requires DB_HOST, DB_PORT, DB_NAME
Index ¶
- Variables
- func Connect()
- type Collection
- func (i *Collection) Aggregate(ctx context.Context, filter bson.D, value interface{}) (err error)
- func (i *Collection) CreateIndex(field string, unique bool)
- func (i *Collection) DeleteOne(ctx context.Context, filter bson.M) (err error)
- func (i *Collection) Find(ctx context.Context, filter bson.M, value interface{}) (err error)
- func (i *Collection) FindOne(ctx context.Context, filter bson.M, value interface{}) (err error)
- func (i *Collection) UpdateOne(ctx context.Context, filter bson.M, value interface{}) (err error)
- type Database
- type Modified
- type MongoError
Constants ¶
This section is empty.
Variables ¶
var DB = new(Database)
DB store the current database connection for use it global in your project.a
var ErrMongoDelete = errors.New("no delete document")
ErrMongoDelete represents an delete error in mongo case
var ErrMongoUpdate = errors.New("no updated document")
ErrMongoUpdate represents an update error in mongo case
Functions ¶
Types ¶
type Collection ¶
Collection represents an mongo db database collection
func NewCollection ¶
func NewCollection(name string) *Collection
NewCollection return a new Collection.
func (*Collection) CreateIndex ¶
func (i *Collection) CreateIndex(field string, unique bool)
CreateIndex creates an index for a given collection.
func (*Collection) DeleteOne ¶
DeleteOne deletes an element from given collection by the bson.M filter.
type Modified ¶
type Modified struct { Updated int64 `json:"updated" bson:"updated` Created int64 `json:"created" bson:"created"` // contains filtered or unexported fields }
Modified represents update and create timestamp for all models.
func NewModified ¶
func NewModified() *Modified
NewModified initial Modified model, cTime is the current time Unix format.
type MongoError ¶
type MongoError struct { Err error `json:"-" bson:"-"` Message string `json:"message" bson:"message"` Filter interface{} `json:"filter" bson:"filter"` Value interface{} `json:"value" bson:"value"` Database string `json:"database" bson:"database"` Collection string `json:"collection" bson:"collection"` Line int `json:"line" bson:"line"` File string `json:"file" bson:"file"` }
MongoError represents the struct of an mongo Error type.
func NewMongoError ¶
func NewMongoError(err error, value interface{}, filter bson.M, database string, collection string) *MongoError
NewMongoError creates an mongo Error for an given parameter set