mongox

package
v0.0.0-...-573f856 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPatchPayload

func BuildPatchPayload(ptr any) bson.M

BuildPatchPayload builds a bson patch payload from a struct pointer.

func BuildPatchPayloadWithParent

func BuildPatchPayloadWithParent(v reflect.Value, parent string) bson.M

BuildPatchPayloadWithParent builds a patch payload with parent key prefix.

func Ptr

func Ptr[T any](val T) *T

Ptr returns a pointer to val.

Types

type CollectionLib

type CollectionLib[P model.IDType, T model.EntityConstraint[P]] struct {
	// contains filtered or unexported fields
}

CollectionLib is a Mongo collection helper with repo options.

func NewCollectionLib

func NewCollectionLib[P model.IDType, T model.EntityConstraint[P]](cls *mongo.Collection) *CollectionLib[P, T]

NewCollectionLib creates a Mongo collection helper for a given entity type.

func (*CollectionLib[P, T]) BatchCreate

func (l *CollectionLib[P, T]) BatchCreate(ctx context.Context, docs []T) error

BatchCreate inserts documents in batch without transactional guarantees.

func (*CollectionLib[P, T]) BatchDelete

func (l *CollectionLib[P, T]) BatchDelete(ctx context.Context, docs []T) (int, error)

BatchDelete deletes documents by ids.

func (*CollectionLib[P, T]) BatchDeleteByFilter

func (l *CollectionLib[P, T]) BatchDeleteByFilter(ctx context.Context, filter bson.M) (cnt int, err error)

BatchDeleteByFilter deletes documents by filter with isolation rules.

func (*CollectionLib[P, T]) BatchDeleteByIDs

func (l *CollectionLib[P, T]) BatchDeleteByIDs(ctx context.Context, ids []P) (cnt int, err error)

BatchDeleteByIDs deletes documents by id list.

func (*CollectionLib[P, T]) BatchUpdate

func (l *CollectionLib[P, T]) BatchUpdate(ctx context.Context, docs []T) error

BatchUpdate updates documents one by one.

func (*CollectionLib[P, T]) Create

func (l *CollectionLib[P, T]) Create(ctx context.Context, doc T) (T, error)

Create inserts a new document with audit fields applied.

func (*CollectionLib[P, T]) Delete

func (l *CollectionLib[P, T]) Delete(ctx context.Context, doc T) (err error)

Delete deletes a document or applies soft delete when enabled.

func (*CollectionLib[P, T]) Find

func (l *CollectionLib[P, T]) Find(ctx context.Context, filter bson.M, opts ...options.Lister[options.FindOptions]) (ret []T, err error)

Find queries documents by filter.

func (*CollectionLib[P, T]) Get

func (l *CollectionLib[P, T]) Get(ctx context.Context, id P) (ret T, err error)

Get fetches one document by id.

func (*CollectionLib[P, T]) GetByFilter

func (l *CollectionLib[P, T]) GetByFilter(ctx context.Context, filter bson.M) (ret T, err error)

GetByFilter fetches one document by filter with optional retry strategy.

func (*CollectionLib[P, T]) GetMergedRepoOpt

func (l *CollectionLib[P, T]) GetMergedRepoOpt(ctx context.Context) *model.RepoOpt

GetMergedRepoOpt merges context repo options with local options.

func (*CollectionLib[P, T]) InjectCond

func (l *CollectionLib[P, T]) InjectCond(ctx context.Context, filter bson.M) (bson.M, error)

InjectCond injects isolation and soft-delete conditions into filter.

func (*CollectionLib[P, T]) PageQuery

func (l *CollectionLib[P, T]) PageQuery(ctx context.Context, input *PageQueryInput) (ret *model.PagedResult[T], err error)

PageQuery performs a paged query with filter, sort, and paging input.

func (*CollectionLib[P, T]) Patch

func (l *CollectionLib[P, T]) Patch(ctx context.Context, doc T) (err error)

Patch updates non-zero fields on a document by id.

func (*CollectionLib[P, T]) PatchRaw

func (l *CollectionLib[P, T]) PatchRaw(ctx context.Context, input *PatchRawInput) (err error)

PatchRaw applies a patch payload with optional filter injection.

func (*CollectionLib[P, T]) Update

func (l *CollectionLib[P, T]) Update(ctx context.Context, doc T) (ret T, err error)

Update replaces a document, using optimistic checks when configured.

func (*CollectionLib[P, T]) Upsert

func (l *CollectionLib[P, T]) Upsert(ctx context.Context, doc T) (ret T, err error)

Upsert replaces or inserts a document.

func (*CollectionLib[P, T]) WithRepoOpt

func (l *CollectionLib[P, T]) WithRepoOpt(opt *model.RepoOpt) *CollectionLib[P, T]

WithRepoOpt sets repo options on the collection helper.

type PageQueryInput

type PageQueryInput struct {
	// Filter is the Mongo filter.
	Filter bson.M
	// Pager is the paging input.
	Pager datax.PagerInfo
	// Sort is the sorting input.
	Sort datax.SortInfo
}

PageQueryInput wraps filter, pager, and sorter for paging queries.

type PatchRawInput

type PatchRawInput struct {
	// Filter is the Mongo filter for patch.
	Filter bson.M
	// PatchPayload is the update payload.
	PatchPayload bson.M
	// IsMany controls UpdateMany vs UpdateOne.
	IsMany bool
	// SkipInjectCond skips isolation and soft delete injection.
	SkipInjectCond bool
}

PatchRawInput defines raw patch parameters.

Jump to

Keyboard shortcuts

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