mongo

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Overview

Package mongo is a generated GoMock package.

Package mongo is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*mongo.Database
	// contains filtered or unexported fields
}

func New

func New(c Config) *Client

func (*Client) Connect

func (c *Client) Connect()

Connect establishes a connection to MongoDB and registers metrics using the provided configuration when the client was Created.

func (*Client) CountDocuments

func (c *Client) CountDocuments(ctx context.Context, collection string, filter interface{}) (int64, error)

CountDocuments counts the number of documents in the specified collection based on the provided filter.

func (*Client) CreateCollection

func (c *Client) CreateCollection(ctx context.Context, name string) error

CreateCollection creates the specified collection in the database.

func (*Client) DeleteMany

func (c *Client) DeleteMany(ctx context.Context, collection string, filter interface{}) (int64, error)

DeleteMany deletes multiple documents from the specified collection based on the provided filter.

func (*Client) DeleteOne

func (c *Client) DeleteOne(ctx context.Context, collection string, filter interface{}) (int64, error)

DeleteOne deletes a single document from the specified collection based on the provided filter.

func (*Client) Drop

func (c *Client) Drop(ctx context.Context, collection string) error

Drop drops the specified collection from the database.

func (*Client) Find

func (c *Client) Find(ctx context.Context, collection string, filter, results interface{}) error

Find retrieves documents from the specified collection based on the provided filter and binds response to result.

func (*Client) FindOne

func (c *Client) FindOne(ctx context.Context, collection string, filter, result interface{}) error

FindOne retrieves a single document from the specified collection based on the provided filter and binds response to result.

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) (any, error)

HealthCheck checks the health of the MongoDB client by pinging the database.

func (*Client) InsertMany

func (c *Client) InsertMany(ctx context.Context, collection string, documents []interface{}) ([]interface{}, error)

InsertMany inserts multiple documents into the specified collection.

func (*Client) InsertOne

func (c *Client) InsertOne(ctx context.Context, collection string, document interface{}) (interface{}, error)

InsertOne inserts a single document into the specified collection.

func (*Client) StartSession

func (c *Client) StartSession() (interface{}, error)

func (*Client) UpdateByID

func (c *Client) UpdateByID(ctx context.Context, collection string, id, update interface{}) (int64, error)

UpdateByID updates a document in the specified collection by its ID.

func (*Client) UpdateMany

func (c *Client) UpdateMany(ctx context.Context, collection string, filter, update interface{}) (int64, error)

UpdateMany updates multiple documents in the specified collection based on the provided filter.

func (*Client) UpdateOne

func (c *Client) UpdateOne(ctx context.Context, collection string, filter, update interface{}) error

UpdateOne updates a single document in the specified collection based on the provided filter.

func (*Client) UseLogger

func (c *Client) UseLogger(logger interface{})

UseLogger sets the logger for the MongoDB client which asserts the Logger interface.

func (*Client) UseMetrics

func (c *Client) UseMetrics(metrics interface{})

UseMetrics sets the metrics for the MongoDB client which asserts the Metrics interface.

func (*Client) UseTracer added in v0.2.0

func (c *Client) UseTracer(tracer any)

UseTracer sets the tracer for the MongoDB client.

type Config

type Config struct {
	Host     string
	User     string
	Password string
	Port     int
	Database string
	// Deprecated Provide Host User Password Port Instead and driver will generate the URI
	URI               string
	ConnectionTimeout time.Duration
}

type Health

type Health struct {
	Status  string                 `json:"status,omitempty"`
	Details map[string]interface{} `json:"details,omitempty"`
}

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(pattern string, args ...interface{})
	Logf(pattern string, args ...interface{})
	Errorf(pattern string, args ...interface{})
}

type Metrics

type Metrics interface {
	NewHistogram(name, desc string, buckets ...float64)

	RecordHistogram(ctx context.Context, name string, value float64, labels ...string)
}

type MockLogger

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

MockLogger is a mock of Logger interface.

func NewMockLogger

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) Debug

func (m *MockLogger) Debug(args ...any)

Debug mocks base method.

func (*MockLogger) Debugf added in v0.3.0

func (m *MockLogger) Debugf(pattern string, args ...any)

Debugf mocks base method.

func (*MockLogger) EXPECT

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLogger) Errorf

func (m *MockLogger) Errorf(pattern string, args ...any)

Errorf mocks base method.

func (*MockLogger) Logf

func (m *MockLogger) Logf(pattern string, args ...any)

Logf mocks base method.

type MockLoggerMockRecorder

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

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) Debug

func (mr *MockLoggerMockRecorder) Debug(args ...any) *gomock.Call

Debug indicates an expected call of Debug.

func (*MockLoggerMockRecorder) Debugf added in v0.3.0

func (mr *MockLoggerMockRecorder) Debugf(pattern any, args ...any) *gomock.Call

Debugf indicates an expected call of Debugf.

func (*MockLoggerMockRecorder) Errorf

func (mr *MockLoggerMockRecorder) Errorf(pattern any, args ...any) *gomock.Call

Errorf indicates an expected call of Errorf.

func (*MockLoggerMockRecorder) Logf

func (mr *MockLoggerMockRecorder) Logf(pattern any, args ...any) *gomock.Call

Logf indicates an expected call of Logf.

type MockMetrics

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

MockMetrics is a mock of Metrics interface.

func NewMockMetrics

func NewMockMetrics(ctrl *gomock.Controller) *MockMetrics

NewMockMetrics creates a new mock instance.

func (*MockMetrics) EXPECT

func (m *MockMetrics) EXPECT() *MockMetricsMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMetrics) NewHistogram

func (m *MockMetrics) NewHistogram(name, desc string, buckets ...float64)

NewHistogram mocks base method.

func (*MockMetrics) RecordHistogram

func (m *MockMetrics) RecordHistogram(ctx context.Context, name string, value float64, labels ...string)

RecordHistogram mocks base method.

type MockMetricsMockRecorder

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

MockMetricsMockRecorder is the mock recorder for MockMetrics.

func (*MockMetricsMockRecorder) NewHistogram

func (mr *MockMetricsMockRecorder) NewHistogram(name, desc any, buckets ...any) *gomock.Call

NewHistogram indicates an expected call of NewHistogram.

func (*MockMetricsMockRecorder) RecordHistogram

func (mr *MockMetricsMockRecorder) RecordHistogram(ctx, name, value any, labels ...any) *gomock.Call

RecordHistogram indicates an expected call of RecordHistogram.

type QueryLog

type QueryLog struct {
	Query      string      `json:"query"`
	Duration   int64       `json:"duration"`
	Collection string      `json:"collection,omitempty"`
	Filter     interface{} `json:"filter,omitempty"`
	ID         interface{} `json:"id,omitempty"`
	Update     interface{} `json:"update,omitempty"`
}

func (*QueryLog) PrettyPrint

func (ql *QueryLog) PrettyPrint(writer io.Writer)

type Transaction

type Transaction interface {
	StartTransaction() error
	AbortTransaction(context.Context) error
	CommitTransaction(context.Context) error
	EndSession(context.Context)
}

Jump to

Keyboard shortcuts

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