mongodbx

package module
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 18 Imported by: 0

README

mongodbx

MongoDB driver extension for Golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignMIne added in v1.0.10

func AssignMIne(key string, value bson.M, parent bson.M) bson.M

AssignMIne Assign bson.M if value is not empty

func AssignStrIne added in v1.0.9

func AssignStrIne(key, value string, parent bson.M) bson.M

AssignStrIne Assign string if value is not empty

func BetweenTime

func BetweenTime(field string, start, end time.Time, m bson.M) bson.M

func BetweenTimeD

func BetweenTimeD(field string, start, end time.Time, d bson.D) bson.D

func CollectionExists

func CollectionExists(db *mongo.Database, coll string) (bool, error)

CollectionExists check if collection exists

func CreateIndex

func CreateIndex(coll *mongo.Collection, imodels []mongo.IndexModel) error

CreateIndex creates indexes for coll

func CreateIndexIfNotExists

func CreateIndexIfNotExists(db *mongo.Database, collname string, indexes map[string]string) (bool, error)

CreateIndexIfNotExists create indexes if collection doesn't exists

func DialCollection

func DialCollection(db *mongo.Database, name string) *mongo.Collection

DialCollection DialCollection

func NullableString added in v1.0.8

func NullableString(s string) interface{}

func TakeClient

func TakeClient(dsn string) (*mongo.Client, error)

func TakeDatabase

func TakeDatabase(dsn string) (*mongo.Database, *mongo.Client, error)

Types

type BaseModel

type BaseModel struct {
	DataSourceName string //data source name
	CollectionName string // collection name
	Type           reflect.Type
	Data           interface{}
	Client         *mongo.Client
	Database       *mongo.Database
	Collection     *mongo.Collection
}

func NewBaseModel

func NewBaseModel(dsn string, data interface{}) (*BaseModel, error)

func NewBaseModelWithCreated

func NewBaseModelWithCreated(dsn string, data interface{}) (*BaseModel, bool, error)

func (*BaseModel) Aggregate

func (b *BaseModel) Aggregate(pipeline []bson.M) (interface{}, error)

func (*BaseModel) Clear

func (b *BaseModel) Clear() error

Clear clear collection

func (*BaseModel) Count

func (b *BaseModel) Count(id string) (int64, error)

func (*BaseModel) CountWhere

func (b *BaseModel) CountWhere(where bson.M) (int64, error)

func (*BaseModel) CountWhereD

func (b *BaseModel) CountWhereD(where bson.D) (int64, error)

func (*BaseModel) Delete

func (b *BaseModel) Delete(id string) (int64, error)

func (*BaseModel) DeleteWhere

func (b *BaseModel) DeleteWhere(where bson.M) (int64, error)

func (*BaseModel) DeleteWhereD

func (b *BaseModel) DeleteWhereD(where bson.D) (int64, error)

func (*BaseModel) Exists

func (b *BaseModel) Exists(id string) (bool, error)

func (*BaseModel) ExistsWhere

func (b *BaseModel) ExistsWhere(where bson.M) (bool, error)

func (*BaseModel) ExistsWhereD

func (b *BaseModel) ExistsWhereD(where bson.D) (bool, error)

func (*BaseModel) Find

func (b *BaseModel) Find(id string) (interface{}, error)

func (*BaseModel) FindWhere

func (b *BaseModel) FindWhere(where bson.M) (interface{}, error)

func (*BaseModel) FindWhereD

func (b *BaseModel) FindWhereD(where bson.D) (interface{}, error)

func (*BaseModel) Insert

func (b *BaseModel) Insert(v interface{}) (string, error)

func (*BaseModel) InsertMany

func (b *BaseModel) InsertMany(v []interface{}) error

func (*BaseModel) QueryWhere

func (b *BaseModel) QueryWhere(where bson.M) (interface{}, error)

func (*BaseModel) QueryWhereD

func (b *BaseModel) QueryWhereD(where bson.D) (interface{}, error)

func (*BaseModel) SumWhere

func (b *BaseModel) SumWhere(match bson.M, field string) (float64, error)

func (*BaseModel) Update

func (b *BaseModel) Update(id string, updator bson.M) (int64, error)

func (*BaseModel) UpdateSet

func (b *BaseModel) UpdateSet(id string, updater bson.M) (int64, error)

func (*BaseModel) UpdateWhere

func (b *BaseModel) UpdateWhere(where bson.M, updator interface{}) (int64, error)

func (*BaseModel) UpdateWhereD

func (b *BaseModel) UpdateWhereD(where bson.D, updator interface{}) (int64, error)

type GroupCountClass added in v1.0.7

type GroupCountClass struct {
	Id    string `bson:"_id"`
	Count int64  `bson:"count"`
}

type Index

type Index struct {
	Unique bool           `bson:"unique"`
	Key    map[string]int `bson:"key"`
	Name   string         `bson:"name"`
}

func (Index) String

func (i Index) String() string

type SumClass

type SumClass struct {
	Sum float64 `bson:"sum"`
}

Jump to

Keyboard shortcuts

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