service

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package service provides business logic layer between API and repository.

Package service provides query operations.

Package service provides write operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateOptions

type AggregateOptions struct {
	Pipeline     bson.A
	AllowDiskUse bool
	BatchSize    int32
}

AggregateOptions contains options for aggregation.

type DocumentService

type DocumentService struct {
	// contains filtered or unexported fields
}

DocumentService handles document operations.

func NewDocumentService

func NewDocumentService(db *mongodb.Client) *DocumentService

NewDocumentService creates a new document service.

func (*DocumentService) CreateDocument

func (s *DocumentService) CreateDocument(ctx context.Context, database, collection string, doc bson.D) (bson.ObjectID, error)

CreateDocument inserts a new document.

func (*DocumentService) DeleteDocument

func (s *DocumentService) DeleteDocument(ctx context.Context, database, collection string, id bson.ObjectID) (int64, error)

DeleteDocument deletes a document by ID.

func (*DocumentService) GetDocument

func (s *DocumentService) GetDocument(ctx context.Context, database, collection string, id bson.ObjectID) (bson.M, error)

GetDocument retrieves a document by ID.

func (*DocumentService) ListDocuments

func (s *DocumentService) ListDocuments(ctx context.Context, database, collection string, filter bson.D, limit, skip int64) ([]bson.M, error)

ListDocuments lists documents with optional filter, limit, and skip.

func (*DocumentService) UpdateDocument

func (s *DocumentService) UpdateDocument(ctx context.Context, database, collection string, id bson.ObjectID, update bson.D, upsert bool) (int64, int64, error)

UpdateDocument updates a document by ID.

type InsertManyResult

type InsertManyResult struct {
	InsertedIDs []bson.ObjectID
}

InsertManyResult contains results from InsertMany.

type QueryOptions

type QueryOptions struct {
	Filter bson.D
	Sort   bson.D
	Limit  int64
	Skip   int64
}

QueryOptions contains options for queries.

type QueryService

type QueryService struct {
	// contains filtered or unexported fields
}

QueryService handles query operations.

func NewQueryService

func NewQueryService(db *mongodb.Client) *QueryService

NewQueryService creates a new query service.

func (*QueryService) Aggregate

func (s *QueryService) Aggregate(ctx context.Context, database, collection string, opts AggregateOptions) ([]bson.M, error)

Aggregate executes an aggregation pipeline.

func (*QueryService) Count

func (s *QueryService) Count(ctx context.Context, database, collection string, filter bson.D) (int64, error)

Count counts documents matching the filter.

func (*QueryService) Distinct

func (s *QueryService) Distinct(ctx context.Context, database, collection, field string, filter bson.D) ([]interface{}, error)

Distinct returns distinct values for a field.

func (*QueryService) Find

func (s *QueryService) Find(ctx context.Context, database, collection string, opts QueryOptions) ([]bson.M, error)

Find executes a find query.

type UpdateManyResult

type UpdateManyResult struct {
	MatchedCount  int64
	ModifiedCount int64
	UpsertedCount int64
	UpsertedID    *bson.ObjectID
}

UpdateManyResult contains results from UpdateMany.

type WriteService

type WriteService struct {
	// contains filtered or unexported fields
}

WriteService handles write operations.

func NewWriteService

func NewWriteService(db *mongodb.Client) *WriteService

NewWriteService creates a new write service.

func (*WriteService) DeleteMany

func (s *WriteService) DeleteMany(ctx context.Context, database, collection string, filter bson.D) (int64, error)

DeleteMany deletes multiple documents.

func (*WriteService) FindOneAndDelete

func (s *WriteService) FindOneAndDelete(ctx context.Context, database, collection string, filter bson.D) (bson.M, error)

FindOneAndDelete finds and deletes a document, returning the deleted document.

func (*WriteService) FindOneAndUpdate

func (s *WriteService) FindOneAndUpdate(ctx context.Context, database, collection string, filter, update bson.D, returnNew bool) (bson.M, error)

FindOneAndUpdate finds and updates a document, returning the result.

func (*WriteService) InsertMany

func (s *WriteService) InsertMany(ctx context.Context, database, collection string, docs []interface{}, ordered bool) (*InsertManyResult, error)

InsertMany inserts multiple documents.

func (*WriteService) UpdateMany

func (s *WriteService) UpdateMany(ctx context.Context, database, collection string, filter, update bson.D, upsert bool) (*UpdateManyResult, error)

UpdateMany updates multiple documents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL