Documentation
¶
Overview ¶
Package mgo provides a MongoDB client.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Collecter ¶ added in v1.1.0
type Collecter[T any] interface { // InsertOne insert one document. InsertOne(ctx context.Context, model T) error // InsertMany insert many documents. InsertMany(ctx context.Context, models []T) error // FindOne find one document. FindOne(ctx context.Context, options ...SetOption) (*T, error) // FindMany find many documents. FindMany(ctx context.Context, options ...SetOption) ([]T, error) // UpdateOne update one document. UpdateOne(ctx context.Context, options ...SetOption) error // UpdateMany update many documents. UpdateMany(ctx context.Context, options ...SetOption) error // DeleteOne delete one document. DeleteOne(ctx context.Context, options ...SetOption) error // DeleteMany delete many documents. DeleteMany(ctx context.Context, options ...SetOption) error // SoftDeleteOne soft delete one document by setting deleted_at. SoftDeleteOne(ctx context.Context, options ...SetOption) error // SoftDeleteMany soft delete many documents by setting deleted_at. SoftDeleteMany(ctx context.Context, options ...SetOption) error // Count count documents. Count(ctx context.Context, options ...SetOption) (int64, error) // Aggregate aggregate documents. Aggregate(ctx context.Context, options ...SetOption) ([]T, error) }
Collecter is a interface for mongo collection.
func NewCollection ¶ added in v1.1.0
func NewCollection[T entiter](c *mongo.Collection) Collecter[T]
NewCollection is a function to create a new collection.
type Entity ¶ added in v1.2.0
type Entity struct {
// ID is a id of entity.
ID primitive.ObjectID `bson:"_id"`
// CreatedAt is a time when entity is created.
CreatedAt time.Time `bson:"created_at"`
// UpdatedAt is a time when entity is updated.
UpdatedAt time.Time `bson:"update_at"`
// DeletedAt is a time when entity is deleted.
// If entity is not deleted, DeletedAt is nil.
DeletedAt *time.Time `bson:"deleted_at"`
}
Entity is a base entity.
type Option ¶ added in v1.1.0
type Option struct {
// Filter is a filter to find.
Filter bson.M
// Update is a update to update.
Update bson.M
// Sort is a sort to sort.
Sort bson.M
// Projection is a projection to projection.
Projection bson.M
// Pipeline is a pipeline to aggregate.
Pipeline []bson.M
// Skip is a skip to skip.
Skip *int64
// Limit is a limit to limit.
Limit *int64
}
Filter is a function to set filter.
Click to show internal directories.
Click to hide internal directories.