Documentation
¶
Index ¶
- Variables
- func CountDocuments(ctx context.Context, ms *mongolks.LinkedService, filter IFilter) (int64, *core.ApplicationError)
- func DeleteMany(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, ...) *core.ApplicationError
- func DeleteOne(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, ...) *core.ApplicationError
- func ExecTransaction(ctx context.Context, ms *mongolks.LinkedService, ...) *core.ApplicationError
- func ExecuteAggregation[T any](ctx context.Context, ls *mongolks.LinkedService, name string, ...) ([]*T, *core.ApplicationError)
- func FilterToJson(filter any) string
- func FindSortOption(s page.SortRequest) options.Lister[options.FindOptions]
- func GenerateAggregation(a *Aggregation, params map[string]any) (mongo.Pipeline, *core.ApplicationError)
- func GetIds(ctx context.Context, ms *mongolks.LinkedService, filter string, ...) ([]string, *core.ApplicationError)
- func GetObjectByFilter[T ICollection](ctx context.Context, ms *mongolks.LinkedService, filter IFilter) (*T, *core.ApplicationError)
- func GetObjectById[T ICollection](ctx context.Context, ms *mongolks.LinkedService, id string) (*T, *core.ApplicationError)
- func GetObjectsByFilter[T ICollection](ctx context.Context, ms *mongolks.LinkedService, filter IFilter) ([]*T, *core.ApplicationError)
- func GetObjectsByFilterSorted[T ICollection](ctx context.Context, ms *mongolks.LinkedService, filter IFilter, ...) ([]*T, *core.ApplicationError)
- func GetPageByFilter[T ICollection](ctx context.Context, ms *mongolks.LinkedService, filter IFilter, ...) ([]T, *core.ApplicationError)
- func GetSequence(ctx context.Context, ms *mongolks.LinkedService, ...) (int, *core.ApplicationError)
- func InsertMany(ctx context.Context, ms *mongolks.LinkedService, objs []ICollection, ...) *core.ApplicationError
- func InsertOne(ctx context.Context, ms *mongolks.LinkedService, obj ICollection, ...) (any, *core.ApplicationError)
- func LoadAggregations(aggregationFolder AggregationsPath, aggregationFiles embed.FS)
- func NewService(config *mongolks.Config, lc fx.Lifecycle, mc Core) (*mongolks.LinkedService, error)
- func PipelineToJson(pipeline mongo.Pipeline) string
- func PrettyPrintJson(jsonStr []byte) (string, error)
- func ReplaceOne(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, ...) *core.ApplicationError
- func SortToBson(s page.SortRequest) bson.D
- func UpdateMany(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, update bson.M, ...) *core.ApplicationError
- func UpdateOne(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, update bson.M, ...) *core.ApplicationError
- func UpdateSingleRecord(ctx context.Context, ms *mongolks.LinkedService, collectionName string, ...) error
- type Aggregation
- type AggregationDirectory
- type AggregationsPath
- type Core
- type GenerateStage
- type ICollection
- type IFilter
- type Stage
Constants ¶
This section is empty.
Variables ¶
View Source
var Aggregations map[string]*Aggregation
Functions ¶
func CountDocuments ¶ added in v0.0.7
func CountDocuments(ctx context.Context, ms *mongolks.LinkedService, filter IFilter) (int64, *core.ApplicationError)
func DeleteMany ¶ added in v0.0.15
func DeleteMany(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, ro ...options.Lister[options.DeleteManyOptions]) *core.ApplicationError
func DeleteOne ¶ added in v0.0.15
func DeleteOne(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, ro ...options.Lister[options.DeleteOneOptions]) *core.ApplicationError
func ExecTransaction ¶ added in v0.0.7
func ExecTransaction(ctx context.Context, ms *mongolks.LinkedService, transaction func(ctx context.Context) error) *core.ApplicationError
func ExecuteAggregation ¶ added in v0.0.4
func ExecuteAggregation[T any](ctx context.Context, ls *mongolks.LinkedService, name string, params map[string]any, opts ...options.Lister[options.AggregateOptions]) ([]*T, *core.ApplicationError)
func ExecuteAggregation(ctx context.Context,ls *mongolks.LinkedService, name string, params map[string]any, opts ...*options.AggregateOptions) (*mongo.Cursor, *core.ApplicationError) {
aggregation, ok := Aggregations[name]
if !ok {
return nil, core.BusinessErrorWithCodeAndMessage("NOT-FOUND", fmt.Sprintf("aggregation '%s' not found", name))
}
mp, err := GenerateAggregation(aggregation, params)
if err != nil {
return nil, err
}
if zerolog.GlobalLevel() < zerolog.DebugLevel {
value := PipelineToJson(mp)
log.Trace().Msg(value)
}
cur, errAgg := ls.GetCollection(aggregation.Collection,"").Aggregate(ctx, mp, opts...)
if errAgg != nil {
if errors.Is(err, mongo.ErrNoDocuments) {
return nil, core.NotFoundError()
}
return nil, core.TechnicalErrorWithError(errAgg)
}
return cur, nil
}
func FilterToJson ¶ added in v0.0.4
func FindSortOption ¶ added in v0.0.16
func FindSortOption(s page.SortRequest) options.Lister[options.FindOptions]
FindSortOption converts a SortRequest into a FindOptions lister ready to be passed as a variadic argument to GetPageByFilter or any Find call.
Usage:
results, err := coremongo.GetPageByFilter(ctx, ms, filter, paging, coremongo.FindSortOption(sortReq))
func GenerateAggregation ¶
func GenerateAggregation(a *Aggregation, params map[string]any) (mongo.Pipeline, *core.ApplicationError)
func GetObjectByFilter ¶ added in v0.0.3
func GetObjectByFilter[T ICollection](ctx context.Context, ms *mongolks.LinkedService, filter IFilter) (*T, *core.ApplicationError)
func GetObjectById ¶ added in v0.0.3
func GetObjectById[T ICollection](ctx context.Context, ms *mongolks.LinkedService, id string) (*T, *core.ApplicationError)
func GetObjectsByFilter ¶ added in v0.0.4
func GetObjectsByFilter[T ICollection](ctx context.Context, ms *mongolks.LinkedService, filter IFilter) ([]*T, *core.ApplicationError)
func GetObjectsByFilterSorted ¶ added in v0.0.6
func GetObjectsByFilterSorted[T ICollection](ctx context.Context, ms *mongolks.LinkedService, filter IFilter, sort page.SortRequest) ([]*T, *core.ApplicationError)
func GetPageByFilter ¶ added in v0.0.15
func GetPageByFilter[T ICollection](ctx context.Context, ms *mongolks.LinkedService, filter IFilter, paging *page.Paging, opts ...options.Lister[options.FindOptions]) ([]T, *core.ApplicationError)
func GetSequence ¶ added in v0.0.7
func GetSequence(ctx context.Context, ms *mongolks.LinkedService, sequenceCollection, sequenceName string) (int, *core.ApplicationError)
func InsertMany ¶ added in v0.0.7
func InsertMany(ctx context.Context, ms *mongolks.LinkedService, objs []ICollection, opts ...options.Lister[options.InsertManyOptions]) *core.ApplicationError
func InsertOne ¶ added in v0.0.7
func InsertOne(ctx context.Context, ms *mongolks.LinkedService, obj ICollection, opts ...options.Lister[options.InsertOneOptions]) (any, *core.ApplicationError)
func LoadAggregations ¶
func LoadAggregations(aggregationFolder AggregationsPath, aggregationFiles embed.FS)
func NewService ¶
func PipelineToJson ¶ added in v0.0.4
func PrettyPrintJson ¶ added in v0.0.4
func ReplaceOne ¶ added in v0.0.7
func ReplaceOne(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, obj ICollection, ro ...options.Lister[options.ReplaceOptions]) *core.ApplicationError
func SortToBson ¶ added in v0.0.16
func SortToBson(s page.SortRequest) bson.D
SortToBson converts a SortRequest to a bson.D. bson.D preserves insertion order, which is required for multi-field sorts.
func UpdateMany ¶ added in v0.0.7
func UpdateMany(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, update bson.M, len int) *core.ApplicationError
func UpdateOne ¶ added in v0.0.7
func UpdateOne(ctx context.Context, ms *mongolks.LinkedService, filter IFilter, update bson.M, opts ...options.Lister[options.UpdateOneOptions]) *core.ApplicationError
func UpdateSingleRecord ¶ added in v0.0.7
Types ¶
type Aggregation ¶
type AggregationDirectory ¶
type AggregationsPath ¶ added in v0.0.7
type AggregationsPath string
type Core ¶
type Core struct {
core.In
AggregationFiles AggregationDirectory `optional:"true"`
AggregationPath *AggregationsPath `optional:"true"`
}
type GenerateStage ¶
type ICollection ¶ added in v0.0.4
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package locker provides a MongoDB-backed implementation of the neutral go-core-app/lock.Locker primitive.
|
Package locker provides a MongoDB-backed implementation of the neutral go-core-app/lock.Locker primitive. |
Click to show internal directories.
Click to hide internal directories.