mongo

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: BSD-3-Clause Imports: 11 Imported by: 61

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppName = "crawlab-db"
View Source
var Client *mongo.Client

Functions

func GetMongoClient added in v0.1.1

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

func GetMongoDb

func GetMongoDb(dbName string) (db *mongo.Database)

func RunTransaction

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

Types

type Col

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

func GetMongoCol

func GetMongoCol(colName string) (col *Col)

func GetMongoColWithDb

func GetMongoColWithDb(colName, dbName string) (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) 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)
}

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) One

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

type FindResultInterface

type FindResultInterface interface {
	One(val interface{}) (err error)
	All(val interface{}) (err error)
}

Jump to

Keyboard shortcuts

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