Documentation ¶
Overview ¶
Package mongo
Package mongo ¶
Package mongo ¶
Package mongo ¶
Package mongo
Index ¶
- Constants
- func ModuleName() string
- type A
- type Collection
- type D
- type E
- type M
- type MetaModel
- type Model
- type Mongo
- func (m *Mongo) Coll(mod Model) *Collection
- func (m *Mongo) Delete(mod Model, data Model) error
- func (m *Mongo) Get(mod Model, filter interface{}) *SingleResult
- func (m *Mongo) GetAll(mod Model, r interface{}, filter interface{}) error
- func (m *Mongo) GetFilter(mod Model, filter interface{}) *SingleResult
- func (m *Mongo) Init() error
- func (m *Mongo) Insert(mod Model, data Model) error
- func (m *Mongo) Persist(mod Model) error
- func (m *Mongo) Update(mod Model, data Model) error
- type Raw
- type SingleResult
Constants ¶
View Source
const (
DefaultTimeout = 5
)
View Source
const (
ErrCheckError = "config check error"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Collection ¶
type Collection struct {
*mgm.Collection
}
type MetaModel ¶
type MetaModel mgm.DefaultModel
MetaModel 不使用bson: inline时 无法正确获取到id 查询返回的结果 不能使用Model decode
type Mongo ¶
type Mongo struct { ContextTimeout int // 超时时间 单位:s DBName string // 连接的库名称 URL string // 数据库连接URI 例如mongodb://localhost:27017 }
Mongo 全局唯一的单例客户端 只能初始化一次使用
func (*Mongo) Get ¶
func (m *Mongo) Get(mod Model, filter interface{}) *SingleResult
Get 语法糖 Coll(model).FindOne(context.Background(), bson.M{filter: key})
func (*Mongo) GetFilter ¶
func (m *Mongo) GetFilter(mod Model, filter interface{}) *SingleResult
GetFilter 通过filter获取 filter 可以为M D E A Raw
Click to show internal directories.
Click to hide internal directories.