mongoqb

package
v0.0.0-...-31ddaea Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoQueryBuilder

type MongoQueryBuilder struct {
	// contains filtered or unexported fields
}

MongoQueryBuilder is a struct to build MongoDB queries and aggregation pipelines.

func NewMongoQueryBuilder

func NewMongoQueryBuilder(collection *mongo.Collection) *MongoQueryBuilder

NewMongoQueryBuilder creates a new instance of MongoQueryBuilder with a given collection.

func (*MongoQueryBuilder) AddConditions

func (x *MongoQueryBuilder) AddConditions(callback func(builder *MongoQueryBuilder)) *MongoQueryBuilder

AddConditions allows multiple WhereGroup callbacks to be added as $match

func (*MongoQueryBuilder) AddStage

func (x *MongoQueryBuilder) AddStage(stage bson.D) *MongoQueryBuilder

AddStage appends a custom stage to the MongoDB aggregation pipeline.

func (*MongoQueryBuilder) Count

func (x *MongoQueryBuilder) Count(ctx context.Context, filter bson.D) (int64, error)

Count returns the number of documents that match the given filter.

func (*MongoQueryBuilder) CountFacet

func (x *MongoQueryBuilder) CountFacet() *MongoQueryBuilder

CountFacet adds a counting stage in the $facet pipeline.

func (*MongoQueryBuilder) DeleteMany

func (x *MongoQueryBuilder) DeleteMany(ctx context.Context, filter bson.M) (*mongo.DeleteResult, error)

DeleteMany deletes multiple documents from the collection.

func (*MongoQueryBuilder) DeleteOne

func (x *MongoQueryBuilder) DeleteOne(ctx context.Context, filter bson.M) (*mongo.DeleteResult, error)

DeleteOne deletes a single document from the collection.

func (*MongoQueryBuilder) Execute

func (x *MongoQueryBuilder) Execute(ctx context.Context) (*mongo.Cursor, error)

Execute runs the aggregation pipeline and returns the cursor.

func (*MongoQueryBuilder) Facet

func (x *MongoQueryBuilder) Facet(facets bson.D) *MongoQueryBuilder

Facet adds a $facet stage to the aggregation pipeline for returning multiple outputs.

func (*MongoQueryBuilder) Find

func (mq *MongoQueryBuilder) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)

Find runs the find operation with the given filter.

func (*MongoQueryBuilder) FindByID

func (x *MongoQueryBuilder) FindByID(ctx context.Context, id interface{}) *mongo.SingleResult

FindByID finds a document by its _id field.

func (*MongoQueryBuilder) FindMany

func (x *MongoQueryBuilder) FindMany(ctx context.Context, filter bson.D, opts ...*options.FindOptions) (*mongo.Cursor, error)

FindMany finds multiple documents matching the given filter.

func (*MongoQueryBuilder) FindOne

func (x *MongoQueryBuilder) FindOne(ctx context.Context, filter bson.M) *mongo.SingleResult

FindOne finds a single document matching the given filter.

func (*MongoQueryBuilder) InsertMany

func (x *MongoQueryBuilder) InsertMany(ctx context.Context, documents []interface{}) (*mongo.InsertManyResult, error)

InsertMany inserts multiple documents into the collection.

func (*MongoQueryBuilder) InsertOne

func (x *MongoQueryBuilder) InsertOne(ctx context.Context, document interface{}) (*mongo.InsertOneResult, error)

InsertOne inserts a single document into the collection.

func (*MongoQueryBuilder) Lookup

func (x *MongoQueryBuilder) Lookup(from, localField, foreignField, as string, pipeline ...bson.A) *MongoQueryBuilder

Lookup adds a $lookup stage to the aggregation pipeline.

func (*MongoQueryBuilder) Match

func (x *MongoQueryBuilder) Match(condition bson.D) *MongoQueryBuilder

Match adds one condition to the pipeline ($match only)

func (*MongoQueryBuilder) NewPipeline

func (x *MongoQueryBuilder) NewPipeline() *MongoQueryBuilder

NewPipeline to start a new pipeline.

func (*MongoQueryBuilder) Paginate

func (x *MongoQueryBuilder) Paginate(page, perPage int) *MongoQueryBuilder

Paginate adds pagination support with page and per_page parameters.

func (*MongoQueryBuilder) Project

func (x *MongoQueryBuilder) Project(projection bson.D) *MongoQueryBuilder

Project adds a $project stage to reshape the documents.

func (*MongoQueryBuilder) ReplaceOne

func (x *MongoQueryBuilder) ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}) (*mongo.UpdateResult, error)

ReplaceOne replaces the entire document that matches the given filter.

func (*MongoQueryBuilder) SearchMultipleFields

func (x *MongoQueryBuilder) SearchMultipleFields(fields []string, searchValue string) *MongoQueryBuilder

SearchMultipleFields adds a search on multiple fields using regex.

func (*MongoQueryBuilder) SearchSingleField

func (x *MongoQueryBuilder) SearchSingleField(field string, searchValue string) *MongoQueryBuilder

SearchSingleField adds a search on a single field using regex.

func (*MongoQueryBuilder) Sort

func (x *MongoQueryBuilder) Sort(field string, ascending bool) *MongoQueryBuilder

Sort adds a $sort stage to sort documents.

func (*MongoQueryBuilder) Unwind

func (x *MongoQueryBuilder) Unwind(path string) *MongoQueryBuilder

Unwind adds a $unwind stage to the aggregation pipeline.

func (*MongoQueryBuilder) UpdateMany

func (x *MongoQueryBuilder) UpdateMany(ctx context.Context, filter bson.D, update bson.D) (*mongo.UpdateResult, error)

UpdateMany updates multiple documents in the collection.

func (*MongoQueryBuilder) UpdateOne

func (x *MongoQueryBuilder) UpdateOne(ctx context.Context, filter bson.D, update bson.D) (*mongo.UpdateResult, error)

UpdateOne updates a single document in the collection.

func (*MongoQueryBuilder) Where

func (x *MongoQueryBuilder) Where(condition *bson.D, field string, operator string, value interface{})

Where adds a single condition to bson.D

func (*MongoQueryBuilder) WhereGroup

func (x *MongoQueryBuilder) WhereGroup(callback func(condition *bson.D)) bson.D

WhereGroup acts as a callback for multiple conditions inside AddConditions

Jump to

Keyboard shortcuts

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