mongox

package
v0.0.0-...-7cf99fd Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorDataExisted = "E11000"                        // 数据已存在
	ErrorDataIsEmpty = "mongo: no documents in result" // 没有查询到数据
)

Variables

This section is empty.

Functions

func Close

func Close()

Close 关闭Mongodb连接

func Collection

func Collection(key string) *mongo.Collection

Collection 获取集合操作对象

func DB

func DB(name string) *mongo.Database

DB 获取数据库操作对象

func IndexExisted

func IndexExisted(coll *mongo.Collection, index string) bool

IndexExisted 检查索引是否存在

func Init

func Init()

Init 初始化mongo数据库

func New

func New(conf Config) *mongo.Client

New 注册mongodb

func NewID

func NewID() primitive.ObjectID

NewID 生成ObjectID

Types

type Config

type Config struct {
	Database   string `mapstructure:"db"`
	Conn       string `mapstructure:"conn"`
	User       string `mapstructure:"user"`
	Password   string `mapstructure:"password"`
	AuthSource string `mapstructure:"auth_source"`
	Timeout    int    `mapstructure:"timeout"`
	MaxPool    int    `mapstructure:"max_pool"`
}

Jump to

Keyboard shortcuts

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