Documentation ¶
Index ¶
- Variables
- type Database
- type DatabaseOptions
- type Field
- type FindAndCountResult
- type FindOption
- type Model
- func (model *Model) BulkWrite(models []mongo.WriteModel) (*mongo.BulkWriteResult, error)
- func (model *Model) DeleteMany(filter interface{}) (*mongo.DeleteResult, error)
- func (model *Model) DeleteOne(filter interface{}) (*mongo.DeleteResult, error)
- func (model *Model) DeleteOneByID(id string) (*mongo.DeleteResult, error)
- func (model *Model) Find(filter interface{}) (result []bson.M, err error)
- func (model *Model) FindAndCount(filter bson.M) (*FindAndCountResult, error)
- func (model *Model) FindOne(filter interface{}) (result *mongo.SingleResult, err error)
- func (model *Model) FindOneAndUpdate(filter interface{}, updates interface{}) (*mongo.SingleResult, error)
- func (model *Model) FindOneByID(id string) (*mongo.SingleResult, error)
- func (model *Model) FindOneByIDAndUpdate(id string, updates interface{}) (*mongo.SingleResult, error)
- func (model *Model) InsertOne(v interface{}) (string, error)
- func (model *Model) Limit(num int64) *Model
- func (model *Model) Populate(collectionName string) *Model
- func (model *Model) Save() error
- func (model *Model) Skip(num int64) *Model
- func (model *Model) SoftDeleteMany(filter interface{}) (*mongo.UpdateResult, error)
- func (model *Model) SoftDeleteOne(filter interface{}) (*mongo.UpdateResult, error)
- func (model *Model) UpdateMany(filter interface{}, updates interface{}) (*mongo.UpdateResult, error)
- type ModelTime
- type Relation
Constants ¶
This section is empty.
Variables ¶
var DB *mongo.Database
DB a mongo database instance after init
Functions ¶
This section is empty.
Types ¶
type Database ¶
Database is a base struct for goose mongo
func NewMongoDatabase ¶
func NewMongoDatabase(ops *DatabaseOptions) (*Database, error)
NewMongoDatabase new a goose mongo database
type DatabaseOptions ¶
type DatabaseOptions struct { ConnectTimeout time.Duration `validate:"isdefault=5"` // Timeout operations after N seconds URL string `validate:"required_without=UsingEnv"` // connection URL string UsingEnv bool `validate:"required_without=URL"` // using env DatabaseName string `validate:"required_without=UsingEnv"` // databaseName // contains filtered or unexported fields }
DatabaseOptions init database options
type FindAndCountResult ¶
FindAndCountResult data struct for FindAndCount
type FindOption ¶
type FindOption struct { options.FindOptions // contains filtered or unexported fields }
FindOption goose custom FindOption extends mongo.options.FindOption
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model Model class
func (*Model) BulkWrite ¶
func (model *Model) BulkWrite(models []mongo.WriteModel) (*mongo.BulkWriteResult, error)
BulkWrite insert batch records
func (*Model) DeleteMany ¶
func (model *Model) DeleteMany(filter interface{}) (*mongo.DeleteResult, error)
DeleteMany delete batch records
func (*Model) DeleteOne ¶
func (model *Model) DeleteOne(filter interface{}) (*mongo.DeleteResult, error)
DeleteOne delete record by filter
func (*Model) DeleteOneByID ¶
func (model *Model) DeleteOneByID(id string) (*mongo.DeleteResult, error)
DeleteOneByID delete record by id
func (*Model) FindAndCount ¶
func (model *Model) FindAndCount(filter bson.M) (*FindAndCountResult, error)
FindAndCount find data and number count
func (*Model) FindOne ¶
func (model *Model) FindOne(filter interface{}) (result *mongo.SingleResult, err error)
FindOne find data by filter
func (*Model) FindOneAndUpdate ¶
func (model *Model) FindOneAndUpdate(filter interface{}, updates interface{}) (*mongo.SingleResult, error)
FindOneAndUpdate find one and update by filter
func (*Model) FindOneByID ¶
func (model *Model) FindOneByID(id string) (*mongo.SingleResult, error)
FindOneByID find data by model.primaryKey
func (*Model) FindOneByIDAndUpdate ¶
func (model *Model) FindOneByIDAndUpdate(id string, updates interface{}) (*mongo.SingleResult, error)
FindOneByIDAndUpdate find one and update by id
func (*Model) SoftDeleteMany ¶
func (model *Model) SoftDeleteMany(filter interface{}) (*mongo.UpdateResult, error)
SoftDeleteMany soft delete batch record
func (*Model) SoftDeleteOne ¶
func (model *Model) SoftDeleteOne(filter interface{}) (*mongo.UpdateResult, error)
SoftDeleteOne soft delete single record
func (*Model) UpdateMany ¶
func (model *Model) UpdateMany(filter interface{}, updates interface{}) (*mongo.UpdateResult, error)
UpdateMany update batch records