mongo

package module
v0.0.0-...-4462017 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerError
	DBError
	QueryError
	ParserError
	ValidationError
)
View Source
const (
	ServerErrorName     = "Server error"
	DBErrorName         = "MongoDB error"
	QueryErrorName      = "Server query error"
	ParserErrorName     = "Server parser error"
	ValidationErrorName = "Server validation error"
)

ServerErrorName and others provides human based definition of the error

Variables

This section is empty.

Functions

func Count

func Count(dbname, collname string, spec bson.M) int

Count gets number records from MongoDB

func GetInt64Value

func GetInt64Value(rec Record, key string) (int64, error)

GetInt64Value function to get int value from record for given key

func GetIntValue

func GetIntValue(rec Record, key string) (int, error)

GetIntValue function to get int value from record for given key

func GetSingleStringValue

func GetSingleStringValue(rec Record, key string) (string, error)

GetSingleStringValue function to get string value from record for given key

func GetStringValue

func GetStringValue(rec Record, key string) (string, error)

GetStringValue function to get string value from record for given key

func GetValue

func GetValue(rec Record, key string) interface{}

GetValue function to get int value from record for given key

func InitMongoDB

func InitMongoDB(uri string)

InitMongoDB initializes MongoDB connection object

func Insert

func Insert(dbname, collname string, records []Record)

Insert records into MongoDB

func MapKeys

func MapKeys(rec Record) []string

MapKeys helper function to return keys from a map

func Remove

func Remove(dbname, collname string, spec bson.M)

Remove records from MongoDB

func Update

func Update(dbname, collname string, spec, newdata bson.M)

Update inplace for given spec

func Upsert

func Upsert(dbname, collname, attr string, records []Record) error

Upsert records into MongoDB

Types

type Connection

type Connection struct {
	Client *mongo.Client
	URI    string
}

Connection defines connection to MongoDB

var Mongo Connection

Mongo holds MongoDB connection

func (*Connection) Connect

func (m *Connection) Connect() *mongo.Client

Connect provides connection to MongoDB

type Record

type Record map[string]interface{}

Record define Mongo record

func ErrorRecord

func ErrorRecord(msg, etype string, ecode int) Record

ErrorRecord provides error record

func Get

func Get(dbname, collname string, spec bson.M, idx, limit int) []Record

Get records from MongoDB

func GetSorted

func GetSorted(dbname, collname string, spec bson.M, skeys []string) []Record

GetSorted records from MongoDB sorted by given key

func (Record) ToJSON

func (r Record) ToJSON() string

ToJSON provides string representation of Record

func (Record) ToString

func (r Record) ToString() string

ToString provides string representation of Record

Jump to

Keyboard shortcuts

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