mongo

package
v0.0.0-...-df570b3 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON(ms interface{}) (string, error)

JSON returns a stringified version of the provided argument using json.Marshal.

func JSONIndent

func JSONIndent(ms interface{}) (string, error)

JSONIndent returns the stringified version of the giving data and indents its result. Uses json.Marshal underneath.

Types

type Config

type Config struct {
	DB       string `toml:"db" json:"db"`
	AuthDB   string `toml:"authdb" json:"authdb"`
	User     string `toml:"user" json:"user"`
	Password string `toml:"password" json:"password"`
	Host     string `toml:"host" json:"host"`
}

Config embodies the data used to connect to user's mongo connection.

func (Config) Empty

func (mgc Config) Empty() bool

Empty returns true/false if all Config values are at default/empty/non-set state.

func (Config) Validate

func (mgc Config) Validate() error

Validate returns an error if the config is invalid.

type MongoDB

type MongoDB struct {
	Config
	// contains filtered or unexported fields
}

MongoDB defines a mongo connection manager that builds allows usage of a giving configuration to generate new mongo sessions and database instances.

func NewMongoDB

func NewMongoDB(conf Config) *MongoDB

NewMongoDB returns a new instance of a MongoDB.

func (*MongoDB) New

func (m *MongoDB) New(isread bool) (*mgo.Database, *mgo.Session, error)

New returns a new session and database from the giving configuration.

Argument:

isread: bool

1. If `isread` is false, then the mgo.Session is cloned so that we re-use the existing sessiby not closing, so others get use ofn connection, in such case, it lets you optimize writes, so try not the session instance connection for other writes.

2. If `isread` is true, then session is copied which creates a new unique session which you should close after use, this lets you handle large reads that may contain complicated queries.

type MongoPull

type MongoPull struct {
	Collection string
	Src        *MongoDB
	// contains filtered or unexported fields
}

MongoPull implements a record pull mechanism which allows you to quickly pull records from the underline mongo collection which will be used for processing.

func (*MongoPull) Pull

func (m *MongoPull) Pull(ctx context.Context, batch int) ([]map[string]interface{}, error)

Pull returns next record from last batch retrieved from underlined collection.

type MongoPush

type MongoPush struct {
	Collection string
	Src        *MongoDB
}

MongoPush implements a record push mechanism which allows you to quickly push new records into the underline mongo collection which will be used for storage.

func (MongoPush) Push

func (m MongoPush) Push(ctx context.Context, recs ...map[string]interface{}) error

Push returns next record from last batch retrieved from underlined collection.

Jump to

Keyboard shortcuts

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