Documentation ¶
Overview ¶
Package gmo implements a simple generic wrapper around the MongoDB driver. Also check https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.
Index ¶
- func DefaultContext() context.Context
- type Collection
- func (c *Collection[T]) CountDocuments(filter any) (int64, error)
- func (c *Collection[T]) Find(ctx context.Context, filter any, opts ...*options.FindOptions) (result []T, err error)
- func (c *Collection[T]) FindByID(ctx context.Context, id string) (result T, err error)
- func (c *Collection[T]) FindOne(ctx context.Context, filter any, opts ...*options.FindOneOptions) (result T, err error)
- func (c *Collection[T]) Insert(document T) (T, error)
- func (c *Collection[T]) UpdateByID(ctx context.Context, id string, document T) error
- func (c *Collection[T]) UpdateOne(ctx context.Context, filter any, document T) error
- type Database
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultContext ¶
DefaultContext creates a context for convenience.
Types ¶
type Collection ¶
type Collection[T any] struct { // contains filtered or unexported fields }
Collection is a generic wrapper around mongo.Collection.
func (*Collection[T]) CountDocuments ¶
func (c *Collection[T]) CountDocuments(filter any) (int64, error)
CountDocuments returns the number of documents in the collection.
func (*Collection[T]) Find ¶
func (c *Collection[T]) Find(ctx context.Context, filter any, opts ...*options.FindOptions) (result []T, err error)
Find executes a find command and returns a slice of the matching documents.
func (*Collection[T]) FindByID ¶
func (c *Collection[T]) FindByID(ctx context.Context, id string) (result T, err error)
FindByID executes a find command based on the ID.
func (*Collection[T]) FindOne ¶
func (c *Collection[T]) FindOne(ctx context.Context, filter any, opts ...*options.FindOneOptions) (result T, err error)
FindOne executes a find command and a document in the collection.
func (*Collection[T]) Insert ¶
func (c *Collection[T]) Insert(document T) (T, error)
Insert executes an insert command to insert a single document into the collection.
func (*Collection[T]) UpdateByID ¶
func (c *Collection[T]) UpdateByID(ctx context.Context, id string, document T) error
UpdateByID executes an update command based on the ID.
type Database ¶
type Database struct { DBName string // contains filtered or unexported fields }
func (*Database) ListCollectionNames ¶
func (d *Database) ListCollectionNames(ctx context.Context, filter any, opts ...*options.ListCollectionsOptions) ([]string, error)
ListCollectionNames lists all the collections in the DB.