db

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidOp     = errors.New("invalid op")
	ErrEmptyInRemove = errors.New("nil in remove")
)
View Source
var TIMEOUT_MILLI_TS = time.Duration(10000)

Functions

func InitConfig

func InitConfig() error

func SetIsTest

func SetIsTest()

func UnsetIsTest

func UnsetIsTest()

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(protocol string, host string, port int, dbname string) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Collection

func (c *Client) Collection(collection string) *Collection

func (*Client) Ping

func (c *Client) Ping() (err error)

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection(name string, db *mongo.Database) *Collection

func (*Collection) Aggregate added in v0.14.0

func (c *Collection) Aggregate(filter interface{}, group interface{}) (ret []bson.M, err error)

func (*Collection) BulkCreateOnly added in v0.4.0

func (c *Collection) BulkCreateOnly(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)

BulkCreateOnly

Mongo update with setOnInsert + upsert operation

func (*Collection) BulkUpdate added in v0.4.0

func (c *Collection) BulkUpdate(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)

BulkUpdate

Mongo update with set + upsert operation

func (*Collection) BulkUpdateOneOnly added in v0.4.0

func (c *Collection) BulkUpdateOneOnly(theList []*UpdatePair) (r *mongo.BulkWriteResult, err error)

BulkUpdateOneOnly

Mongo update with set + no-upsert operation

func (*Collection) BulkUpdateOneOnlyNoSet added in v0.4.0

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 added in v0.4.0

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 added in v0.8.0

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 added in v0.14.0

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 added in v0.14.0

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 added in v0.4.0

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 added in v0.26.0

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 added in v0.14.0

func (c *Collection) UpdateOneOnlyNoSet(filter interface{}, update interface{}) (r *mongo.UpdateResult, err error)

UpdateOneOnlyNoSet

Mongo update-one with no-upsert operation

type UpdatePair added in v0.4.0

type UpdatePair struct {
	Filter interface{}
	Update interface{}
}

Jump to

Keyboard shortcuts

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