Documentation ¶
Index ¶
- Constants
- Variables
- func BulkWrite(ctx context.Context, c *mongo.Collection, models []mongo.WriteModel, ...) (*mongo.BulkWriteResult, error)
- func Count(ctx context.Context, c *mongo.Collection, filter any, ...) (int64, error)
- func DecodeAll(ctx context.Context, cur *mongo.Cursor, docs any) error
- func DecodeOne(r *mongo.SingleResult, doc any) error
- func ExtractDatabaseName(uri string) (string, error)
- func Find[T any](ctx context.Context, c *mongo.Collection, filter any, ...) (docs []T, err error)
- func FindOne[T any](ctx context.Context, c *mongo.Collection, filter any, ...) (doc T, err error)
- func NewClient(ctx context.Context, uri string) (*mongo.Client, error)
- func Pagination(index int64, size int64) *options.FindOptions
- func Remove(ctx context.Context, c *mongo.Collection, filter any, ...) error
- func RemoveMany(ctx context.Context, c *mongo.Collection, filter any, ...) error
- func Save(ctx context.Context, c *mongo.Collection, filter any, update any, ...) (*mongo.UpdateResult, error)
- func SaveMany(ctx context.Context, c *mongo.Collection, filter any, update any, ...) (*mongo.UpdateResult, error)
- func ToBson(doc any) (bson.M, error)
- type Config
- type Database
Constants ¶
View Source
const ( ErrMsgDecode = "failed to decode document due to error: %w" ErrMsgQuery = "failed to execute query due to error: %w" ErrMsgMarshal = "failed to marshal document due to error: %w" ErrMsgUnmarshal = "failed to unmarshal document due to error: %w" )
View Source
const ( ErrMsgClient = "failed to create mongodb client due to error: %w" ErrMsgDatabase = "failed to create mongodb database due to error: %w" )
Variables ¶
View Source
var ErrNoDB = errors.New("database name not found in URI")
View Source
var Timeout = 5 * time.Second
Functions ¶
func BulkWrite ¶
func BulkWrite(ctx context.Context, c *mongo.Collection, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)
func Count ¶
func Count(ctx context.Context, c *mongo.Collection, filter any, opts ...*options.CountOptions) (int64, error)
func ExtractDatabaseName ¶
func Find ¶
func Find[T any](ctx context.Context, c *mongo.Collection, filter any, opts ...*options.FindOptions) (docs []T, err error)
func FindOne ¶
func FindOne[T any](ctx context.Context, c *mongo.Collection, filter any, opts ...*options.FindOneOptions) (doc T, err error)
func Pagination ¶
func Pagination(index int64, size int64) *options.FindOptions
func Remove ¶
func Remove(ctx context.Context, c *mongo.Collection, filter any, opts ...*options.DeleteOptions) error
func RemoveMany ¶
func RemoveMany(ctx context.Context, c *mongo.Collection, filter any, opts ...*options.DeleteOptions) error
func Save ¶
func Save(ctx context.Context, c *mongo.Collection, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
func SaveMany ¶
func SaveMany(ctx context.Context, c *mongo.Collection, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
Types ¶
Click to show internal directories.
Click to hide internal directories.