Documentation ¶
Index ¶
- Variables
- func InitConfig() error
- func SetIsTest()
- func UnsetIsTest()
- type Client
- type Collection
- func (c *Collection) Aggregate(filter interface{}, group interface{}) (ret []bson.M, err error)
- func (c *Collection) BulkCreateOnly(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)
- func (c *Collection) BulkUpdate(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)
- func (c *Collection) BulkUpdateOneOnly(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)
- func (c *Collection) BulkUpdateOneOnlyNoSet(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)
- func (c *Collection) Count(filter interface{}, n int64) (count int64, err error)
- func (c *Collection) CreateIndex(keys *bson.D, opts *options.IndexOptions) (err error)
- func (c *Collection) CreateOnly(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
- func (c *Collection) CreateUniqueIndex(keys *bson.D) (err error)
- func (c *Collection) Drop() (err error)
- func (c *Collection) Find(filter interface{}, n int64, ret interface{}, project interface{}, ...) (err error)
- func (c *Collection) FindOne(filter interface{}, ret interface{}, project interface{}) (err error)
- func (c *Collection) FindOneAndUpdate(filter interface{}, update interface{}, isNew bool) (r *mongo.SingleResult, err error)
- func (c *Collection) FindOneAndUpdateNoSet(filter interface{}, update interface{}, isNew bool) (r *mongo.SingleResult, err error)
- func (c *Collection) Remove(filter bson.M) (err error)
- func (c *Collection) Update(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
- func (c *Collection) UpdateManyOnly(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
- func (c *Collection) UpdateManyOnlyNoSet(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
- func (c *Collection) UpdateOneOnly(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
- func (c *Collection) UpdateOneOnlyNoSet(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
- type UpdatePair
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidOp = errors.New("invalid op") ErrEmptyInRemove = errors.New("nil in remove") )
var TIMEOUT_MILLI_TS = time.Duration(10000)
Functions ¶
func InitConfig ¶
func InitConfig() error
func UnsetIsTest ¶
func UnsetIsTest()
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Collection ¶
func (c *Client) Collection(collection string) *Collection
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
func NewCollection ¶
func NewCollection(name string, db *mongo.Database) *Collection
func (*Collection) Aggregate ¶
func (c *Collection) Aggregate(filter interface{}, group interface{}) (ret []bson.M, err error)
func (*Collection) BulkCreateOnly ¶
func (c *Collection) BulkCreateOnly(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)
BulkCreateOnly
Mongo update with setOnInsert + upsert operation
func (*Collection) BulkUpdate ¶
func (c *Collection) BulkUpdate(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)
BulkUpdate
Mongo update with set + upsert operation
func (*Collection) BulkUpdateOneOnly ¶
func (c *Collection) BulkUpdateOneOnly(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)
BulkUpdateOneOnly
Mongo update with set + no-upsert operation
func (*Collection) BulkUpdateOneOnlyNoSet ¶
func (c *Collection) BulkUpdateOneOnlyNoSet(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)
BulkUpdateOneOnlyNoSet
Mongo update without set and no-upsert operation WARNING!!! Must ensure that the update part is with $set, $unset, $setOnInsert.
func (*Collection) Count ¶
func (c *Collection) Count(filter interface{}, n int64) (count int64, err error)
Count
func (*Collection) CreateIndex ¶
func (c *Collection) CreateIndex(keys *bson.D, opts *options.IndexOptions) (err error)
func (*Collection) CreateOnly ¶
func (c *Collection) CreateOnly(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
CreateOnly
Mongo update-one with setOnInsert + upsert operation
func (*Collection) CreateUniqueIndex ¶
func (c *Collection) CreateUniqueIndex(keys *bson.D) (err error)
func (*Collection) Drop ¶
func (c *Collection) Drop() (err error)
func (*Collection) Find ¶
func (c *Collection) Find(filter interface{}, n int64, ret interface{}, project interface{}, sort interface{}) (err error)
Find
Never return error with normal operations. need to check len for not-found.
Params:
ret: return values, requiring passing with pointer (malloced in cur.All) project: the empty struct of the return type.
ex:
query := make(map[string]interface{}) query["test"] = 1 var ret []*Temp //!!! declare but initiate Find(query, 4, &ret, &Temp{})
func (*Collection) FindOne ¶
func (c *Collection) FindOne(filter interface{}, ret interface{}, project interface{}) (err error)
FindOne
Params:
ret: return value. project: the empty struct of the return type.
ex:
query := make(map[string]interface{}) query["test"] = 1 ret := &Temp{} FindOne(query, ret, nil)
Err:
mongo.ErrNoDocuments if not found.
func (*Collection) FindOneAndUpdate ¶
func (c *Collection) FindOneAndUpdate(filter interface{}, update interface{}, isNew bool) (r *mongo.SingleResult, err error)
FindOneAndUpdate
Mongo update-one with set + no-upsert operation
func (*Collection) FindOneAndUpdateNoSet ¶
func (c *Collection) FindOneAndUpdateNoSet(filter interface{}, update interface{}, isNew bool) (r *mongo.SingleResult, err error)
FindOneAndUpdate
Mongo update-one with set + no-upsert operation
func (*Collection) Remove ¶
func (c *Collection) Remove(filter bson.M) (err error)
Remove
Params:
filter: filter. Must pass with non-empty map.
func (*Collection) Update ¶
func (c *Collection) Update(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
Update
Mongo update with set + upsert operation
func (*Collection) UpdateManyOnly ¶
func (c *Collection) UpdateManyOnly(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
UpdateManyOnly
Mongo update-many with set + no-upsert operation
func (*Collection) UpdateManyOnlyNoSet ¶
func (c *Collection) UpdateManyOnlyNoSet(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
UpdateManyOnly
Mongo update-many with set + no-upsert operation
func (*Collection) UpdateOneOnly ¶
func (c *Collection) UpdateOneOnly(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
UpdateOneOnly
Mongo update-one with set + no-upsert operation
func (*Collection) UpdateOneOnlyNoSet ¶
func (c *Collection) UpdateOneOnlyNoSet(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)
UpdateOneOnlyNoSet
Mongo update-one with no-upsert operation
type UpdatePair ¶
type UpdatePair struct { Filter interface{} Update interface{} }