Documentation ¶
Index ¶
- Variables
- func CombAndFilters(filters ...interface{}) bson.M
- func CombOrFilters(filters ...interface{}) bson.M
- func CombineFilters(operator string, filters ...interface{}) bson.M
- func ConvertFilter(v interface{}, fatherTag string) bson.M
- func ConvertId(id interface{}) (oid primitive.ObjectID, err error)
- func ConvertSliceFilter(value reflect.Value, tag string) bson.M
- func Eq(field string, value interface{}) bson.M
- func Gt(field string, value interface{}) bson.M
- func Gte(field string, value interface{}) bson.M
- func IdFilter(id primitive.ObjectID) bson.M
- func In(field string, value interface{}) bson.M
- func Lt(field string, value interface{}) bson.M
- func Lte(field string, value interface{}) bson.M
- func Ne(field string, value interface{}) bson.M
- func Nin(field string, value interface{}) bson.M
- func Now() *time.Time
- func ParseFilter(filter interface{}) interface{}
- func Set(doc interface{}) bson.M
- func SimpleStructToDoc(v interface{}) (doc *bsoncore.Document, err error)
- func UnDeletedFilterByID(id primitive.ObjectID) bson.M
- func UndeleteFilter() bson.M
- type Document
- type IDocument
- type Mongo
- func (m *Mongo) Client() *mongo.Client
- func (m *Mongo) CountDocuments(filter IDocument, opts ...*options.CountOptions) (count int64, err error)
- func (m *Mongo) DB() *mongo.Database
- func (m *Mongo) DeleteMany(filter IDocument, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
- func (m *Mongo) DeleteOne(filter IDocument, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
- func (m *Mongo) DriverCollection(name string, opts ...*options.CollectionOptions) *mongo.Collection
- func (m *Mongo) Find(filter, results interface{}, opts ...*options.FindOptions) (err error)
- func (m *Mongo) FindByID(id, result interface{}, opts ...*options.FindOneOptions) (err error)
- func (m *Mongo) FindOne(filter, result interface{}, opts ...*options.FindOneOptions) (err error)
- func (m *Mongo) FindOneAndDelete(filter IDocument, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult
- func (m *Mongo) FindOneAndReplace(filter interface{}, replacement IDocument, ...) *mongo.SingleResult
- func (m *Mongo) FindOneAndUpdate(filter interface{}, update IDocument, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult
- func (m *Mongo) FindOneUndeleteByFilter(filter, result interface{}, opts ...*options.FindOneOptions) (err error)
- func (m *Mongo) FindUnDeleteByID(id, result interface{}, opts ...*options.FindOneOptions) (err error)
- func (m *Mongo) FindUndeleteByFilter(filter, results interface{}, opts ...*options.FindOptions) (err error)
- func (m *Mongo) InsertMany(docs []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)
- func (m *Mongo) InsertOne(doc IDocument, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
- func (m *Mongo) Release(ctx context.Context) error
- func (m *Mongo) UpdateByID(id interface{}, update IDocument, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
- func (m *Mongo) UpdateMany(filter interface{}, update IDocument, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
- func (m *Mongo) UpdateOne(filter interface{}, update IDocument, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( CollectionNameNotFound = errors.New("when filter is not IDocument, then need CollectionName option") InvalidDocument = errors.New("invalid document impl IDocument interface at least") )
Functions ¶
func CombAndFilters ¶
func CombOrFilters ¶
func CombineFilters ¶
CombineFilters 用来组合多个bson.M filter operator : $and $or ...
func ConvertFilter ¶
ConvertFilter convert Struct or Ptr to bson.M
func ConvertSliceFilter ¶ added in v0.1.8
func ParseFilter ¶
func ParseFilter(filter interface{}) interface{}
ParseFilter 检查filter并进行转化. 转化为 driver 支持的格式 如果本身就是 bson.M 或 bson.D 系列则不进行转化 如果是结构体或者结构体指针则进行转化 (支持复杂结构体)
func SimpleStructToDoc ¶
SimpleStructToDoc 没有嵌套的结构体可以使用此方法进行转化
func UndeleteFilter ¶
Types ¶
type Document ¶
type Document struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` CreatedAt *time.Time `bson:"created_at,omitempty" json:"created_at,omitempty"` UpdatedAt *time.Time `bson:"updated_at,omitempty" json:"updated_at,omitempty"` DeletedAt *time.Time `bson:"deleted_at,omitempty" json:"-"` }
type IDocument ¶
type IDocument interface { PreCreate() PreUpdate() PreDelete() CollectionName() string }
type Mongo ¶
type Mongo struct {
// contains filtered or unexported fields
}
func (*Mongo) CountDocuments ¶ added in v0.1.6
func (*Mongo) DeleteMany ¶
func (m *Mongo) DeleteMany(filter IDocument, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
DeleteMany 删除多条数据 如果你希望使用bson当作filter,那么建议使用driver的原始方法
func (*Mongo) DeleteOne ¶
func (m *Mongo) DeleteOne(filter IDocument, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
DeleteOne 删除一条数据 如果你希望使用bson当作filter,那么建议使用driver的原始方法
func (*Mongo) DriverCollection ¶ added in v0.1.5
func (m *Mongo) DriverCollection(name string, opts ...*options.CollectionOptions) *mongo.Collection
DriverCollection 提供原始查询方法
func (*Mongo) Find ¶
func (m *Mongo) Find(filter, results interface{}, opts ...*options.FindOptions) (err error)
Find 基础查找 filter 支持 bson 以及 IDocument 如果filter 是一个 Document 那么他必须是 addressable 的, 也就是说是一个指针. result 则是一个 存储结果的指针 例如 &[]SomeDoc or make([]SomeDoc,0)
func (*Mongo) FindByID ¶
func (m *Mongo) FindByID(id, result interface{}, opts ...*options.FindOneOptions) (err error)
FindByID 通过id查找数据
func (*Mongo) FindOne ¶
func (m *Mongo) FindOne(filter, result interface{}, opts ...*options.FindOneOptions) (err error)
FindOne 查找一条数据 filter 支持 bson 以及 IDocument result 则是一个 存储结果的指针 例如 &SomeDoc
func (*Mongo) FindOneAndDelete ¶ added in v0.1.6
func (m *Mongo) FindOneAndDelete(filter IDocument, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult
FindOneAndDelete 如果你希望使用bson当作filter,那么建议使用driver的原始方法
func (*Mongo) FindOneAndReplace ¶ added in v0.1.6
func (m *Mongo) FindOneAndReplace(filter interface{}, replacement IDocument, opts ...*options.FindOneAndReplaceOptions) *mongo.SingleResult
func (*Mongo) FindOneAndUpdate ¶ added in v0.1.6
func (m *Mongo) FindOneAndUpdate(filter interface{}, update IDocument, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult
func (*Mongo) FindOneUndeleteByFilter ¶
func (m *Mongo) FindOneUndeleteByFilter(filter, result interface{}, opts ...*options.FindOneOptions) (err error)
FindOneUndeleteByFilter 查找一条未删除的数据
func (*Mongo) FindUnDeleteByID ¶
func (m *Mongo) FindUnDeleteByID(id, result interface{}, opts ...*options.FindOneOptions) (err error)
FindUnDeleteByID 查找一条未删除的数据
func (*Mongo) FindUndeleteByFilter ¶
func (m *Mongo) FindUndeleteByFilter(filter, results interface{}, opts ...*options.FindOptions) (err error)
FindUndeleteByFilter 查找未删除的所有数据
func (*Mongo) InsertMany ¶
func (m *Mongo) InsertMany(docs []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)
InsertMany 插入多条数据
func (*Mongo) InsertOne ¶
func (m *Mongo) InsertOne(doc IDocument, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
InsertOne 插入一条数据
func (*Mongo) UpdateByID ¶
func (m *Mongo) UpdateByID(id interface{}, update IDocument, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
UpdateByID 通过ID更新 支持 string 或 objectId
func (*Mongo) UpdateMany ¶
func (m *Mongo) UpdateMany(filter interface{}, update IDocument, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
UpdateMany 更新多条数据
func (*Mongo) UpdateOne ¶
func (m *Mongo) UpdateOne(filter interface{}, update IDocument, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
UpdateOne 更新一条数据