mongo

package
v0.0.0-...-0485310 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: BSD-3-Clause Imports: 13 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppName = "crawlab-db"

Functions

func GetMongoClient

func GetMongoClient(opts ...ClientOption) (c *mongo.Client, err error)

func GetMongoDb

func GetMongoDb(dbName string, opts ...DbOption) (db *mongo.Database)

func RunTransaction

func RunTransaction(fn func(mongo.SessionContext) error) (err error)

func RunTransactionWithContext

func RunTransactionWithContext(ctx context.Context, fn func(mongo.SessionContext) error) (err error)

Types

type ClientOption

type ClientOption func(options *ClientOptions)

func WithAuthMechanism

func WithAuthMechanism(value string) ClientOption

func WithAuthSource

func WithAuthSource(value string) ClientOption

func WithContext

func WithContext(ctx context.Context) ClientOption

func WithDb

func WithDb(value string) ClientOption

func WithHost

func WithHost(value string) ClientOption

func WithHosts

func WithHosts(value []string) ClientOption

func WithPassword

func WithPassword(value string) ClientOption

func WithPort

func WithPort(value int) ClientOption

func WithUri

func WithUri(value string) ClientOption

func WithUsername

func WithUsername(value string) ClientOption

type ClientOptions

type ClientOptions struct {
	Context                 context.Context
	Uri                     string
	Host                    string
	Port                    int
	Db                      string
	Hosts                   []string
	Username                string
	Password                string
	AuthSource              string
	AuthMechanism           string
	AuthMechanismProperties map[string]string
}

type Col

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

func GetMongoCol

func GetMongoCol(colName string) (col *Col)

func GetMongoColWithDb

func GetMongoColWithDb(colName string, db *mongo.Database) (col *Col)

func (*Col) Aggregate

func (col *Col) Aggregate(pipeline mongo.Pipeline, opts *options.AggregateOptions) (fr *FindResult)

func (*Col) Count

func (col *Col) Count(query bson.M) (total int, err error)

func (*Col) CreateIndex

func (col *Col) CreateIndex(indexModel mongo.IndexModel) (err error)

func (*Col) CreateIndexes

func (col *Col) CreateIndexes(indexModels []mongo.IndexModel) (err error)

func (*Col) Delete

func (col *Col) Delete(query bson.M) (err error)

func (*Col) DeleteAllIndexes

func (col *Col) DeleteAllIndexes() (err error)

func (*Col) DeleteId

func (col *Col) DeleteId(id primitive.ObjectID) (err error)

func (*Col) DeleteIndex

func (col *Col) DeleteIndex(name string) (err error)

func (*Col) DeleteWithOptions

func (col *Col) DeleteWithOptions(query bson.M, opts *options.DeleteOptions) (err error)

func (*Col) Find

func (col *Col) Find(query bson.M, opts *FindOptions) (fr *FindResult)

func (*Col) FindId

func (col *Col) FindId(id primitive.ObjectID) (fr *FindResult)

func (*Col) GetCollection

func (col *Col) GetCollection() (c *mongo.Collection)

func (*Col) GetContext

func (col *Col) GetContext() (ctx context.Context)

func (*Col) GetName

func (col *Col) GetName() (name string)

func (*Col) Insert

func (col *Col) Insert(doc interface{}) (id primitive.ObjectID, err error)

func (*Col) InsertMany

func (col *Col) InsertMany(docs []interface{}) (ids []primitive.ObjectID, err error)

func (*Col) ListIndexes

func (col *Col) ListIndexes() (indexes []map[string]interface{}, err error)

func (*Col) MustCreateIndex

func (col *Col) MustCreateIndex(indexModel mongo.IndexModel)

func (*Col) MustCreateIndexes

func (col *Col) MustCreateIndexes(indexModels []mongo.IndexModel)

func (*Col) Replace

func (col *Col) Replace(query bson.M, doc interface{}) (err error)

func (*Col) ReplaceId

func (col *Col) ReplaceId(id primitive.ObjectID, doc interface{}) (err error)

func (*Col) ReplaceWithOptions

func (col *Col) ReplaceWithOptions(query bson.M, doc interface{}, opts *options.ReplaceOptions) (err error)

func (*Col) Update

func (col *Col) Update(query bson.M, update interface{}) (err error)

func (*Col) UpdateId

func (col *Col) UpdateId(id primitive.ObjectID, update interface{}) (err error)

func (*Col) UpdateWithOptions

func (col *Col) UpdateWithOptions(query bson.M, update interface{}, opts *options.UpdateOptions) (err error)

type ColInterface

type ColInterface interface {
	Insert(doc interface{}) (id primitive.ObjectID, err error)
	InsertMany(docs []interface{}) (ids []primitive.ObjectID, err error)
	UpdateId(id primitive.ObjectID, update interface{}) (err error)
	Update(query bson.M, update interface{}) (err error)
	UpdateWithOptions(query bson.M, update interface{}, opts *options.UpdateOptions) (err error)
	ReplaceId(id primitive.ObjectID, doc interface{}) (err error)
	Replace(query bson.M, doc interface{}) (err error)
	ReplaceWithOptions(query bson.M, doc interface{}, opts *options.ReplaceOptions) (err error)
	DeleteId(id primitive.ObjectID) (err error)
	Delete(query bson.M) (err error)
	DeleteWithOptions(query bson.M, opts *options.DeleteOptions) (err error)
	Find(query bson.M, opts *FindOptions) (fr *FindResult)
	FindId(id primitive.ObjectID) (fr *FindResult)
	Count(query bson.M) (total int, err error)
	Aggregate(pipeline mongo.Pipeline, opts *options.AggregateOptions) (fr *FindResult)
	CreateIndex(indexModel mongo.IndexModel) (err error)
	CreateIndexes(indexModels []mongo.IndexModel) (err error)
	MustCreateIndex(indexModel mongo.IndexModel)
	MustCreateIndexes(indexModels []mongo.IndexModel)
	DeleteIndex(name string) (err error)
	DeleteAllIndexes() (err error)
	ListIndexes() (indexes []map[string]interface{}, err error)
	GetContext() (ctx context.Context)
	GetName() (name string)
	GetCollection() (c *mongo.Collection)
}

type DbOption

type DbOption func(options *DbOptions)

func WithDbClient

func WithDbClient(c *mongo.Client) DbOption

type DbOptions

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

type FindOptions

type FindOptions struct {
	Skip  int
	Limit int
	Sort  bson.D
}

type FindResult

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

func NewFindResult

func NewFindResult() (fr *FindResult)

func NewFindResultWithError

func NewFindResultWithError(err error) (fr *FindResult)

func (*FindResult) All

func (fr *FindResult) All(val interface{}) (err error)

func (*FindResult) GetCol

func (fr *FindResult) GetCol() (col *Col)

func (*FindResult) GetCursor

func (fr *FindResult) GetCursor() (cur *mongo.Cursor)

func (*FindResult) GetError

func (fr *FindResult) GetError() (err error)

func (*FindResult) GetSingleResult

func (fr *FindResult) GetSingleResult() (res *mongo.SingleResult)

func (*FindResult) One

func (fr *FindResult) One(val interface{}) (err error)

type FindResultInterface

type FindResultInterface interface {
	One(val interface{}) (err error)
	All(val interface{}) (err error)
	GetCol() (col *Col)
	GetSingleResult() (res *mongo.SingleResult)
	GetCursor() (cur *mongo.Cursor)
	GetError() (err error)
}

Jump to

Keyboard shortcuts

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