mongodb

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	Name    string                 `json:"name"`
	IdIndex map[string]interface{} `json:"idIndex"`
	Info    map[string]interface{} `json:"info"`
	Type    string                 `json:"type"`
	Options map[string]interface{} `json:"options"`
}

type Config

type Config struct {
	Address        string `json:"address"`
	Username       string `json:"username,omitempty"`
	Password       string `json:"password,omitempty"`
	MinPoolSize    int    `json:"minPoolSize,omitempty"`
	MaxPoolSize    int    `json:"maxPoolSize,omitempty"`
	ConnectTimeout int    `json:"connectTimeout,omitempty"` // 客户端连接超时 单位 毫秒
	CertPath       string `json:"certPath,omitempty"`
}

type Database

type Database struct {
	Name       string `json:"name"`
	SizeOnDisk int64  `json:"sizeOnDisk"`
	Empty      bool   `json:"empty"`
}

type IService

type IService interface {
	Close()
	Databases() (databases []*Database, totalSize int64, err error)
	DatabaseDelete(database string) (err error)
	Collections(database string) (collections []*Collection, err error)
	CollectionCreate(database string, collection string, opts ...*options.CreateCollectionOptions) (err error)
	CollectionDelete(database string, collection string) (err error)
	Indexes(database string, collection string) (indexes []map[string]interface{}, err error)
	IndexCreate(database string, collection string, index mongo.IndexModel) (name string, err error)
	IndexesCreate(database string, collection string, indexes []mongo.IndexModel) (names []string, err error)
	IndexDelete(database string, collection string, name string) (err error)
	IndexDeleteAll(database string, collection string) (err error)
	Insert(database string, collection string, document interface{}, opts ...*options.InsertOneOptions) (insertedId interface{}, err error)
	BatchInsert(database string, collection string, documents []interface{}, opts ...*options.InsertManyOptions) (insertedIds []interface{}, err error)
	Update(database string, collection string, id interface{}, update interface{}, opts ...*options.UpdateOptions) (updateResult *UpdateResult, err error)
	UpdateOne(database string, collection string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (updateResult *UpdateResult, err error)
	BatchUpdate(database string, collection string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (updateResult *UpdateResult, err error)
	Count(database string, collection string, filter interface{}) (totalCount int64, err error)
	QueryMap(database string, collection string, filter interface{}, opts *options.FindOptions) (list []map[string]interface{}, err error)
	QueryMapPage(database string, collection string, filter interface{}, page *Page, opts *options.FindOptions) (list []map[string]interface{}, err error)
	QueryMapPageResult(database string, collection string, filter interface{}, page *Page, opts *options.FindOptions) (pageResult *Page, err error)
	DeleteOne(database string, collection string, filter interface{}) (deletedCount int64, err error)
	DeleteMany(database string, collection string, filter interface{}) (deletedCount int64, err error)
}

func New

func New(config *Config) (IService, error)

New 创建 mongodb 客户端

type Page

type Page struct {
	PageSize   int64         `json:"pageSize"`
	PageNo     int64         `json:"pageNo"`
	TotalCount int64         `json:"totalCount"`
	TotalPage  int64         `json:"totalPage"`
	List       []interface{} `json:"list"`
}

type Service

type Service struct {
	*Config
	// contains filtered or unexported fields
}

func (*Service) BatchInsert

func (this_ *Service) BatchInsert(database string, collection string, documents []interface{}, opts ...*options.InsertManyOptions) (insertedIds []interface{}, err error)

func (*Service) BatchUpdate

func (this_ *Service) BatchUpdate(database string, collection string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (updateResult *UpdateResult, err error)

func (*Service) Close

func (this_ *Service) Close()

func (*Service) CollectionCreate added in v1.2.11

func (this_ *Service) CollectionCreate(database string, collection string, opts ...*options.CreateCollectionOptions) (err error)

func (*Service) CollectionDelete added in v1.2.11

func (this_ *Service) CollectionDelete(database string, collection string) (err error)

func (*Service) Collections

func (this_ *Service) Collections(database string) (collections []*Collection, err error)

func (*Service) Count added in v1.2.11

func (this_ *Service) Count(database string, collection string, filter interface{}) (totalCount int64, err error)

func (*Service) DatabaseDelete added in v1.2.12

func (this_ *Service) DatabaseDelete(database string) (err error)

func (*Service) Databases

func (this_ *Service) Databases() (databases []*Database, totalSize int64, err error)

func (*Service) DeleteMany added in v1.2.12

func (this_ *Service) DeleteMany(database string, collection string, filter interface{}) (deletedCount int64, err error)

func (*Service) DeleteOne added in v1.2.12

func (this_ *Service) DeleteOne(database string, collection string, filter interface{}) (deletedCount int64, err error)

func (*Service) GetServers

func (this_ *Service) GetServers() []string

func (*Service) IndexCreate added in v1.2.11

func (this_ *Service) IndexCreate(database string, collection string, index mongo.IndexModel) (name string, err error)

func (*Service) IndexDelete added in v1.2.11

func (this_ *Service) IndexDelete(database string, collection string, name string) (err error)

func (*Service) IndexDeleteAll added in v1.2.11

func (this_ *Service) IndexDeleteAll(database string, collection string) (err error)

func (*Service) Indexes

func (this_ *Service) Indexes(database string, collection string) (indexes []map[string]interface{}, err error)

func (*Service) IndexesCreate added in v1.2.11

func (this_ *Service) IndexesCreate(database string, collection string, indexes []mongo.IndexModel) (names []string, err error)

func (*Service) Insert

func (this_ *Service) Insert(database string, collection string, document interface{}, opts ...*options.InsertOneOptions) (insertedId interface{}, err error)

func (*Service) QueryMap

func (this_ *Service) QueryMap(database string, collection string, filter interface{}, opts *options.FindOptions) (list []map[string]interface{}, err error)

func (*Service) QueryMapPage

func (this_ *Service) QueryMapPage(database string, collection string, filter interface{}, page *Page, opts *options.FindOptions) (list []map[string]interface{}, err error)

func (*Service) QueryMapPageResult

func (this_ *Service) QueryMapPageResult(database string, collection string, filter interface{}, page *Page, opts *options.FindOptions) (pageResult *Page, err error)

func (*Service) Update

func (this_ *Service) Update(database string, collection string, id interface{}, update interface{}, opts ...*options.UpdateOptions) (updateResult *UpdateResult, err error)

func (*Service) UpdateOne

func (this_ *Service) UpdateOne(database string, collection string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (updateResult *UpdateResult, err error)

type UpdateResult

type UpdateResult struct {
	MatchedCount  int64       `json:"matchedCount"`
	ModifiedCount int64       `json:"modifiedCount"`
	UpsertedCount int64       `json:"upsertedCount"`
	UpsertedID    interface{} `json:"upsertedID"`
}

Jump to

Keyboard shortcuts

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