mongo

package
v0.0.0-...-a5a6d41 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotFound is returned when the document was not found in Mongo collection
	ErrNotFound = errors.New("Document not found")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	AppName          string   `json:"appName,omitempty"`
	Name             string   `json:"name,omitempty"`
	Host             []string `json:"host,omitempty"`
	Port             string   `json:"port,omitempty"`
	ConnectionString string   `json:"connectionString,omitempty"`
	AuthSource       string   `json:"authSource,omitempty"`
	ReplicaSet       string   `json:"replicaSet,omitempty"`

	Username       string             `json:"username,omitempty"`
	Password       string             `json:"password,omitempty"`
	Direct         bool               `json:"direct,omitempty"`
	Timeout        time.Duration      `json:"timeout,omitempty"`
	ReadPreference mgo.ReadPreference `json:"readPreference,omitempty"`
}

Config holds the config required for MongoDB

type Handler

type Handler struct {
	DBName string
	// contains filtered or unexported fields
}

Handler DB Sessions are maintained inside a struct for better caching of the data stores developed based on the stackoverflow answer: http://stackoverflow.com/questions/26574594/best-practice-to-maintain-a-mgo-session

func New

func New(c Config) (*Handler, error)

New returns a new MongoDB handler instance with all the configurations set

func (*Handler) Delete

func (ms *Handler) Delete(collectionName string, query interface{}) error

Delete deletes the first document matching the given query

func (*Handler) Find

func (ms *Handler) Find(collectionName string, query, selectFields interface{}, sort []string, start, limit int, result interface{}) ([]map[string]interface{}, error)

Find finds all records matching the query

func (*Handler) FindOne

func (ms *Handler) FindOne(collectionName string, query, selectFields interface{}, sort []string, result interface{}) (map[string]interface{}, error)

FindOne finds and returns the first matching document based on the provided query

func (*Handler) InsertInfo

func (ms *Handler) InsertInfo(collectionName string, data interface{}) (string, error)

InsertInfo inserts a new document and return inserted document's ID

func (*Handler) Update

func (ms *Handler) Update(collectionName string, query, data interface{}) error

Update updates the first document matching the query

Jump to

Keyboard shortcuts

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