Documentation
¶
Overview ¶
Package service provides business logic layer between API and repository.
Package service provides query operations.
Package service provides write operations.
Index ¶
- type AggregateOptions
- type DocumentService
- func (s *DocumentService) CreateDocument(ctx context.Context, database, collection string, doc bson.D) (bson.ObjectID, error)
- func (s *DocumentService) DeleteDocument(ctx context.Context, database, collection string, id bson.ObjectID) (int64, error)
- func (s *DocumentService) GetDocument(ctx context.Context, database, collection string, id bson.ObjectID) (bson.M, error)
- func (s *DocumentService) ListDocuments(ctx context.Context, database, collection string, filter bson.D, ...) ([]bson.M, error)
- func (s *DocumentService) UpdateDocument(ctx context.Context, database, collection string, id bson.ObjectID, ...) (int64, int64, error)
- type InsertManyResult
- type QueryOptions
- type QueryService
- func (s *QueryService) Aggregate(ctx context.Context, database, collection string, opts AggregateOptions) ([]bson.M, error)
- func (s *QueryService) Count(ctx context.Context, database, collection string, filter bson.D) (int64, error)
- func (s *QueryService) Distinct(ctx context.Context, database, collection, field string, filter bson.D) ([]interface{}, error)
- func (s *QueryService) Find(ctx context.Context, database, collection string, opts QueryOptions) ([]bson.M, error)
- type UpdateManyResult
- type WriteService
- func (s *WriteService) DeleteMany(ctx context.Context, database, collection string, filter bson.D) (int64, error)
- func (s *WriteService) FindOneAndDelete(ctx context.Context, database, collection string, filter bson.D) (bson.M, error)
- func (s *WriteService) FindOneAndUpdate(ctx context.Context, database, collection string, filter, update bson.D, ...) (bson.M, error)
- func (s *WriteService) InsertMany(ctx context.Context, database, collection string, docs []interface{}, ...) (*InsertManyResult, error)
- func (s *WriteService) UpdateMany(ctx context.Context, database, collection string, filter, update bson.D, ...) (*UpdateManyResult, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregateOptions ¶
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.
type InsertManyResult ¶
InsertManyResult contains results from InsertMany.
type QueryOptions ¶
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.