Documentation ¶
Overview ¶
Package vmdb
Index ¶
- func ErrNoDocuments(err error) bool
- func UpdateInc(value interface{}) bson.D
- func UpdateSet(value interface{}) bson.D
- type Collection
- func (i *Collection) Aggregate(ctx context.Context, filter mongo.Pipeline, value interface{}) (err error)
- func (i *Collection) AggregateOne(ctx context.Context, pipeline mongo.Pipeline, value interface{}) (err error)
- func (i *Collection) CountDocuments(ctx context.Context, filter bson.D) (count int64, err error)
- func (i *Collection) CreateIndex(field string, unique bool) *Collection
- func (i *Collection) CreateMultiIndex(filter bson.D, unique bool) *Collection
- func (i *Collection) DeleteMany(ctx context.Context, filter bson.D) (err error)
- func (i *Collection) DeleteOne(ctx context.Context, filter bson.D) (err error)
- func (i *Collection) Find(ctx context.Context, filter bson.D, value interface{}) (err error)
- func (i *Collection) FindOne(ctx context.Context, filter bson.D, value interface{}) (err error)
- func (i *Collection) InsertMany(ctx context.Context, value []interface{}) (err error)
- func (i *Collection) InsertOne(ctx context.Context, value interface{}) (err error)
- func (i *Collection) TryDeleteMany(ctx context.Context, filter bson.D) (err error)
- func (i *Collection) TryDeleteOne(ctx context.Context, filter bson.D) (err error)
- func (i *Collection) TryUpdateMany(ctx context.Context, filter bson.A, value bson.M) (err error)
- func (i *Collection) TryUpdateOne(ctx context.Context, filter bson.D, value interface{}) (err error)
- func (i *Collection) UpdateMany(ctx context.Context, filter bson.A, value bson.M) (err error)
- func (i *Collection) UpdateOne(ctx context.Context, filter bson.D, value interface{}, result interface{}) (err error)
- func (i *Collection) UpdateOneAggregate(ctx context.Context, filter bson.D, value interface{}, result interface{}, ...) (err error)
- type Database
- type DeletedResult
- type Filter
- func (i *Filter) Append(value bson.E)
- func (i *Filter) Bson() bson.D
- func (i *Filter) ContainsString(key string, value string)
- func (i *Filter) ElemMatch(list string, key string, value string)
- func (i *Filter) ElemMatchList(list string, key string, value []string)
- func (i *Filter) EqualBool(key string, value string)
- func (i *Filter) EqualInt(key string, value string)
- func (i *Filter) EqualInt64(key string, value string)
- func (i *Filter) EqualString(key string, value string)
- func (i *Filter) EqualStringList(key string, value []string)
- func (i *Filter) ExpIn(key string, value string)
- func (i *Filter) GteInt(key string, value string)
- func (i *Filter) GteInt64(key string, value string)
- func (i *Filter) LikeString(key string, value string)
- func (i *Filter) LteInt(key string, value string)
- func (i *Filter) LteInt64(key string, value string)
- func (i *Filter) SearchString(fields []string, value string) bson.D
- type Pipeline
- func (i *Pipeline) Append(entry bson.D)
- func (i *Pipeline) AppendSlice(pipe []bson.D)
- func (i *Pipeline) Count() *Pipeline
- func (i *Pipeline) Limit(value int64, defaultValue int64) *Pipeline
- func (i *Pipeline) Lookup(from string, localField string, foreignField string, as string)
- func (i *Pipeline) LookupList(from string, localField string, foreignField string, as string)
- func (i *Pipeline) LookupMatch(from string, localField string, foreignField string, as string, match bson.D)
- func (i *Pipeline) LookupUnwind(from string, localField string, foreignField string, as string)
- func (i *Pipeline) LookupUnwindMatch(from string, localField string, foreignField string, as string, match bson.D)
- func (i *Pipeline) Match(filter bson.D) *Pipeline
- func (i *Pipeline) Skip(value int64, defaultValue int64) *Pipeline
- func (i *Pipeline) Sort(value bson.D) *Pipeline
- func (i *Pipeline) SortFields(sort bson.D) *Pipeline
- type Sort
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrNoDocuments ¶ added in v1.4.1
ErrNoDocuments return true if the error is an mongo.ErrNoDocuments error. Else the function returns false.
Types ¶
type Collection ¶
type Collection struct { Name string DatabaseName string Collection *mongo.Collection }
Collection represents an mongo db database collection
func (*Collection) Aggregate ¶
func (i *Collection) Aggregate(ctx context.Context, filter mongo.Pipeline, value interface{}) (err error)
Aggregate use the mongo.Collection.Aggregate function for select a list of elements using an aggregation pipeline.
func (*Collection) AggregateOne ¶ added in v1.4.1
func (i *Collection) AggregateOne(ctx context.Context, pipeline mongo.Pipeline, value interface{}) (err error)
AggregateOne use an aggregation pipeline for creating an struct that contains the information from more than one collection. If the result cursor contains objects, the first one will be decoded in the value param.
func (*Collection) CountDocuments ¶ added in v1.4.26
CountDocuments count all documents filtered by the filter object.
func (*Collection) CreateIndex ¶
func (i *Collection) CreateIndex(field string, unique bool) *Collection
CreateIndex creates an index for a given collection.
func (*Collection) CreateMultiIndex ¶ added in v1.4.0
func (i *Collection) CreateMultiIndex(filter bson.D, unique bool) *Collection
CreateMultiIndex creates an index for an value combination.
func (*Collection) DeleteMany ¶ added in v1.4.0
DeleteMany deletes all elements from collection they match the filter object.
func (*Collection) DeleteOne ¶
DeleteOne deletes an element from given collection by the bson.M filter.
func (*Collection) Find ¶
Find use the mongo.Collection.Find function for select a list of elements from a collection. The result will decode in the value param. So the value need to be a slice struct.
func (*Collection) FindOne ¶
FindOne use the mongo.Collection.FindOne function for select one element from collection.
func (*Collection) InsertMany ¶ added in v1.4.0
func (i *Collection) InsertMany(ctx context.Context, value []interface{}) (err error)
InsertMany inserts a list of value and return an MongoError as error.
func (*Collection) InsertOne ¶ added in v1.4.0
func (i *Collection) InsertOne(ctx context.Context, value interface{}) (err error)
InsertOne inserts a value and return an MongoError as error.
func (*Collection) TryDeleteMany ¶ added in v1.4.1
TryDeleteMany returns no error if no element was deleted.
func (*Collection) TryDeleteOne ¶ added in v1.4.1
DeleteOne deletes an element from given collection by the bson.M filter.
func (*Collection) TryUpdateMany ¶ added in v1.4.1
TryUpdateMany returns no error if no models was updated.
func (*Collection) TryUpdateOne ¶ added in v1.4.1
func (i *Collection) TryUpdateOne(ctx context.Context, filter bson.D, value interface{}) (err error)
TryUpdateOne returns no error if the model is not updated.
func (*Collection) UpdateMany ¶ added in v1.4.0
UpdateMany updates an slice of interfaces. @TODO: create an result.
func (*Collection) UpdateOne ¶
func (i *Collection) UpdateOne(ctx context.Context, filter bson.D, value interface{}, result interface{}) (err error)
UpdateOne use the mongo.Collection.UpdateOne function for update one element in an collection. If the result.MatchedCount == 0, the function returns an mongo.ErrNoDocuments error. If the result.MatchedCount != 0, the i.Collection.FindOne function is used to select the updated element and decode it into the result interface.
func (*Collection) UpdateOneAggregate ¶ added in v1.4.2
func (i *Collection) UpdateOneAggregate(ctx context.Context, filter bson.D, value interface{}, result interface{}, pipeline mongo.Pipeline) (err error)
UpdateOneAggregate works the same way than UpdateOne but you can define the pipeline param for decode an aggregated model into the result interface.
type Database ¶
type Database struct { Name string //Database Name URI string //Database URI Database *mongo.Database }
Database represents the initial struct for an Mongo Database connection named Name. Database is an pointer to an mongo.Database.
func NewDatabase ¶ added in v1.4.0
func (*Database) Collection ¶ added in v1.4.0
func (i *Database) Collection(name string) *Collection
Collection initial an new mongodb collection named by the name parameter. Use NewDatabase for initial an database connection.
func (*Database) Connect ¶ added in v1.4.6
Connect creates an mongo db client and initial an connection.
You can use the following parameters as environment variable or as flag to define the connection parameters.
MONGO_DB_HOST=<host>, MONGO_DB_PORT=<port>, MONGO_DB_USER=<user>, MONGO_DB_PASSWORD=<password>
if the username or password is not defined, the Client try to connect without an user.
type DeletedResult ¶ added in v1.4.0
type Filter ¶ added in v1.4.1
Filter represents an mongo filter object.
func (*Filter) ContainsString ¶ added in v1.4.28
ContainsString use regex for handling a substring matching.
MongoDB:
{ key: {"$regex": .*value.*} }
func (*Filter) ElemMatchList ¶ added in v1.4.4
ElemMatchList TODO
func (*Filter) EqualBool ¶ added in v1.4.4
EqualBool the value is a string representation of an bool. match if value is equal to the value of the key in a database entry.
MongoDB:
{ key: value as boolean }
func (*Filter) EqualInt ¶ added in v1.4.1
EqualInt the value is an string representation of an int. match if the value is equal to the value of the given key in an database entry.
MongoDB:
{ key: value as int }
func (*Filter) EqualInt64 ¶ added in v1.4.4
EqualInt the value is an string representation of an int64. match if value is equal to the value of the key in a database entry.
MongoDB:
{ key: value as int64 }
func (*Filter) EqualString ¶ added in v1.4.1
EqualString match if the value is equal to the value of the key in a database collection.
MongoDB:
{ key: value }
func (*Filter) EqualStringList ¶ added in v1.4.1
EqualStringList match if the the value of the key param is matching an element in the value param slice.
MongoDB:
{ key: {"$or": value} }
func (*Filter) GteInt ¶ added in v1.4.1
GteInt provides $lte for key they have an int6 datatype. If the value element is "" or not an int formated string no element will be added to the filter object.
MongoDB:
{ key: {"$gte": value as int} }
func (*Filter) GteInt64 ¶ added in v1.4.1
GteInt64 provides $gte for key they have an int64 datatype. If the value element is "" or not an int64 formated string no element will be added to the filter object.
MongoDB:
{ key: {"$gte": value as int64} }
func (*Filter) LikeString ¶ added in v1.4.4
LikeString use regex for handling a substring matching at the start of a string.
MongoDB:
{ key: {"$regex": ^value} }
func (*Filter) LteInt ¶ added in v1.4.1
LteInt provides $lte for key they have an int datatype. If the value element is "" or not an int formated string no element will be added to the filter object.
MongoDB:
{ key: {"$lte": value as int} }
func (*Filter) LteInt64 ¶ added in v1.4.1
LteInt64 provides $lte for key they have an int64 datatype. If the value element is "" or not an int64 formated string no element will be added to the filter object.
MongoDB:
{ key: {"$lte": value as int64} }
func (*Filter) SearchString ¶ added in v1.4.28
SearchString searchs for a given string in all the given fields If the value search string is "" no search string will be added to the filter object.
MongoDB:
{ key: {"$or": key: {"$regex": ".*value.*"}} }
type Pipeline ¶ added in v1.4.0
Pipeline represents an helper for handling mongodb pipeline. The Pipe param contains an []bson.D that represents an mongo pipeline.
func NewPipeline ¶ added in v1.4.0
func NewPipeline() *Pipeline
NewPipeline creates an new Pipeline struct.
func (*Pipeline) AppendSlice ¶ added in v1.4.18
Append appends the elements in pipe to the the Pipeline object.
func (*Pipeline) Count ¶ added in v1.4.32
Count adds the value total as $count to the end of the Pipeline struct.
MongoDB:
{"$count": total}
func (*Pipeline) Lookup ¶ added in v1.4.0
Lookup represents an lookup to join an list of elements from a second collection to the result.
MongoDB:
{ "$lookup":{ "from": from, "localField": localField, "foreignField" foreignField, "as": as } }
func (*Pipeline) LookupList ¶ added in v1.4.2
LookupList represents an lookup to join an list of elements from a second collection to the result. The value of the localField need to be a list of references. If the foreignField value is in the list, the element will joined to the as value.
MongoDB:
{ "$lookup":{ "from": from, "let": { localField: $localField }, "foreignField" foreignField, "pipeline": [{ "$match":{ "$expr":{"$in: ["$foreinField", "$$localField"]} } }], "as": as } }
func (*Pipeline) LookupMatch ¶ added in v1.4.1
func (i *Pipeline) LookupMatch(from string, localField string, foreignField string, as string, match bson.D)
LookupMatch represents an lookup to join an list of elements from a second collection to the result. The joined elements can be filtered by the match param.
MongoDB:
{ "$lookup":{ "from": from, "localField": localField, "foreignField" foreignField, "pipeline": [{"$match": match}] "as": as } }
func (*Pipeline) LookupUnwind ¶ added in v1.4.0
LockupUnwind represents the lookup and unwind combination to join an element from a second collection to the result.
MongoDB:
{ "$lookup":{ "from": from, "localField": localField, "foreignField" foreignField, "as": as }, "$unwind": { "path": "$as", "preserveNullAndEmptyArrays": true } }
func (*Pipeline) LookupUnwindMatch ¶ added in v1.4.1
func (i *Pipeline) LookupUnwindMatch(from string, localField string, foreignField string, as string, match bson.D)
LookupUnwindMatch represents the lookup and unwind combination to join an element from a second collection to the result. The joined element can be filtered by the match param.
MongoDB:
{ "$lookup":{ "from": from, "localField": localField, "foreignField" foreignField, "pipeline": [{"$match": match}] "as": as }, "$unwind": { "path": "$as", "preserveNullAndEmptyArrays": true } }
func (*Pipeline) Match ¶ added in v1.4.0
Match adds the filter param as $match to the end of the Pipeline struct.
MongoDB:
{"$match": filter}