mongodb

package
v1.2.15 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CONFIG = MongoDB{
	DB:      "mongo_test",
	Timeout: 10,
	Addr:    "localhost:27017",
}

Functions

func IsExist

func IsExist() bool

IsExist config file is exist

func Recover added in v1.2.0

func Recover() error

Recover

func Remove

func Remove() error

Remove remove config file

Types

type Client

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

func GetClient

func GetClient(ctx context.Context) (*Client, error)

ctx, cancel := context.WithTimeout(context.Background(), CONFIG.Timeout*time.Second) GetClient

func (*Client) Aggregate

func (c *Client) Aggregate(ctx context.Context, name string, groupStage mongo.Pipeline) ([]bson.M, error)

Aggregate

func (*Client) DeleteOne

func (c *Client) DeleteOne(ctx context.Context, name string, filter interface{}) error

DeleteOne

func (*Client) Disconnect

func (c *Client) Disconnect(ctx context.Context) error

Disconnect

func (*Client) Find

func (c *Client) Find(ctx context.Context, name string, filters ...interface{}) ([]bson.M, error)

Find

func (*Client) FindOne

func (c *Client) FindOne(ctx context.Context, name string, filter interface{}) *mongo.SingleResult

FindOne

func (*Client) InsertOne

func (c *Client) InsertOne(ctx context.Context, name string, filter interface{}) (interface{}, error)

InsertOne

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping

func (*Client) UpdateOne

func (c *Client) UpdateOne(ctx context.Context, name string, filter, update interface{}) (*mongo.UpdateResult, error)

UpdateByID

type MongoDB

type MongoDB struct {
	Timeout time.Duration `mapstructure:"timeout" json:"timeout" yaml:"timeout"`
	DB      string        `mapstructure:"db" json:"db" yaml:"db"`
	Addr    string        `mapstructure:"addr" json:"addr" yaml:"addr"`
}

func (*MongoDB) GetApplyURI

func (md *MongoDB) GetApplyURI() string

Jump to

Keyboard shortcuts

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