Documentation ¶
Index ¶
- func ObjectIDFromHexIDString(str *string) (primitive.ObjectID, error)
- type Client
- func (c *Client) Close() error
- func (c *Client) ComplexTransaction(ctx context.Context, callback MongoTx) (any, error)
- func (c *Client) GetCollection(name string) (*mongo.Collection, error)
- func (c *Client) GetConnection() *mongo.Client
- func (c *Client) StandardTransaction(ctx context.Context, callback MongoTx) error
- func (c *Client) StartDbSegment(ctx context.Context, name, collectionName string) *newrelic.DatastoreSegment
- func (c *Client) Validate() error
- type IClient
- type InMemoryTestDbClient
- type MongoTx
- type Option
- func WithClientOptions(clientOptions *options.ClientOptions) Option
- func WithCollectionNames(collectionNames []string) Option
- func WithConnectionURI(connectionURI string) Option
- func WithDatabaseName(databaseName string) Option
- func WithLogger(logger *zap.Logger) Option
- func WithMaxConnectionAttempts(maxConnectionAttempts int) Option
- func WithMaxRetriesPerOperation(maxRetriesPerOperation int) Option
- func WithOperationSleepInterval(operationSleepInterval time.Duration) Option
- func WithQueryTimeout(queryTimeout time.Duration) Option
- func WithRetryTimeOut(retryTimeOut time.Duration) Option
- func WithTelemetry(telemetry *instrumentation.Client) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ObjectIDFromHexIDString ¶
ObjectIDFromHexIDString takes a pointer to a string as input and returns a primitive.ObjectID and an error. It converts the input string, which is expected to be a hexadecimal representation of an ObjectID, to a primitive.ObjectID. The function is a method of the MongoDatabase struct and can be used to convert a string representation of an ObjectID to a primitive.ObjectID that can be used in MongoDB queries.
Types ¶
type Client ¶
type Client struct { // Conn serves as the database co Conn *mongo.Client // Logger is the logging utility used by this object Logger *zap.Logger // MaxConnectionAttempts outlines the maximum connection attempts // to initiate against the database MaxConnectionAttempts int // MaxRetriesPerOperation defines the maximum retries to attempt per failed database // connection attempt MaxRetriesPerOperation int // RetryTimeOut defines the maximum time until a retry operation is observed as a // timed out operation RetryTimeOut time.Duration // OperationSleepInterval defines the amount of time between retry operations // that the system sleeps OperationSleepInterval time.Duration // QueryTimeout defines the maximal amount of time a query can execute before being cancelled QueryTimeout time.Duration // Telemetry defines the object by which we will emit metrics, trace requests, and database operations Telemetry *instrumentation.Client // DatabaseName database name DatabaseName *string // CollectionNames is a list of collection names CollectionNames []string // ClientOptions defines the options to use when connecting to the database ClientOptions *options.ClientOptions // ConnectionURI defines the connection string to use when connecting to the database ConnectionURI *string // contains filtered or unexported fields }
func (*Client) ComplexTransaction ¶
ComplexTransaction is a wrapper around the `WithTransaction` method of the `mongo.Session` object.
func (*Client) GetCollection ¶
func (c *Client) GetCollection(name string) (*mongo.Collection, error)
GetCollection returns a collection object by name
func (*Client) GetConnection ¶
GetConnection returns the database connection
func (*Client) StandardTransaction ¶
StandardTransaction is a wrapper around the `WithTransaction` method of the `mongo.Session` object.
func (*Client) StartDbSegment ¶
func (c *Client) StartDbSegment(ctx context.Context, name, collectionName string) *newrelic.DatastoreSegment
StartDbSegment starts a new `newrelic.DatastoreSegment` for database operations. It takes in a context, a name for the operation, and a collection name as parameters. If telemetry is enabled, it retrieves the transaction from the context and starts a new datastore segment for the operation using the `StartNosqlDatastoreSegment` method from the `Telemetry` object. It returns the newly created segment. If telemetry is not enabled, it returns `nil`.
type InMemoryTestDbClient ¶
func NewInMemoryTestDbClient ¶
func NewInMemoryTestDbClient(collectionNames []string) (*InMemoryTestDbClient, error)
NewInMemoryTestDbClient creates a new in-memory MongoDB database and returns a client to it.
func (*InMemoryTestDbClient) Teardown ¶
func (c *InMemoryTestDbClient) Teardown() error
Teardown cleans up resources initialized by Setup. This function must be called once after all tests have finished running.
type MongoTx ¶
type MongoTx func(sessCtx mongo.SessionContext) (any, error)
MongoTx is a type alias for the `WithTransaction` method of the `mongo.Session` object.
type Option ¶
type Option func(*Client)
func WithClientOptions ¶
func WithClientOptions(clientOptions *options.ClientOptions) Option
WithClientOptions sets the client options
func WithCollectionNames ¶
WithCollectionNames sets the collection names
func WithConnectionURI ¶
WithConnectionURI sets the connection URI
func WithDatabaseName ¶
WithDatabaseName sets the database name
func WithLogger ¶
WithLogger sets the logging utility used by this object
func WithMaxConnectionAttempts ¶
WithMaxConnectionAttempts sets the maximum connection attempts to initiate against the database
func WithMaxRetriesPerOperation ¶
WithMaxRetriesPerOperation sets the maximum retries to attempt per failed database connection attempt
func WithOperationSleepInterval ¶
WithOperationSleepInterval sets the amount of time between retry operations that the system sleeps
func WithQueryTimeout ¶
WithQueryTimeout sets the maximal amount of time a query can execute before being cancelled
func WithRetryTimeOut ¶
WithRetryTimeOut sets the maximum time until a retry operation is observed as a timed out operation
func WithTelemetry ¶
func WithTelemetry(telemetry *instrumentation.Client) Option
WithTelemetry sets the object by which we will emit metrics, trace requests, and database operations