Documentation ¶
Index ¶
- Constants
- func Count(dbname, collname string, spec map[string]any) int
- func Distinct(dbname, collname, field string) ([]any, error)
- func ErrorRecord(msg, etype string, ecode int) map[string]any
- func Get(dbname, collname string, spec map[string]any, idx, limit int) []map[string]any
- func GetInt64Value(rec map[string]any, key string) (int64, error)
- func GetIntValue(rec map[string]any, key string) (int, error)
- func GetSingleStringValue(rec map[string]any, key string) (string, error)
- func GetSorted(dbname, collname string, spec map[string]any, skeys []string, ...) []map[string]any
- func GetStringValue(rec map[string]any, key string) (string, error)
- func GetValue(rec map[string]any, key string) interface{}
- func InitMongoDB(uri string)
- func Insert(dbname, collname string, records []map[string]any)
- func InsertAny(dbname, collname string, records []any)
- func InsertRecord(dbname, collname string, rec map[string]any) error
- func MapKeys(rec map[string]any) []string
- func Remove(dbname, collname string, spec map[string]any) error
- func Update(dbname, collname string, spec, newdata map[string]any)
- func Upsert(dbname, collname, attr string, records []map[string]any) error
- func UpsertAny(dbname, collname string, records []any) error
- func UpsertRecord(dbname, collname string, spec, rec map[string]any) error
- type Connection
- type MongoDB
- func (d *MongoDB) Count(dbname, collname string, spec map[string]any) int
- func (d *MongoDB) Distinct(dbname, collname, field string) ([]any, error)
- func (d *MongoDB) Get(dbname, collname string, spec map[string]any, idx, limit int) []map[string]any
- func (d *MongoDB) GetSorted(dbname, collname string, spec map[string]any, skeys []string, ...) []map[string]any
- func (d *MongoDB) InitDB(uri string)
- func (d *MongoDB) Insert(dbname, collname string, records []map[string]any)
- func (d *MongoDB) InsertRecord(dbname, collname string, rec map[string]any) error
- func (d *MongoDB) Remove(dbname, collname string, spec map[string]any) error
- func (d *MongoDB) Update(dbname, collname string, spec, newdata map[string]any)
- func (d *MongoDB) Upsert(dbname, collname, attr string, records []map[string]any) error
Constants ¶
const ( ServerError DBError QueryError ParserError ValidationError )
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 ErrorRecord ¶
ErrorRecord provides error record
func GetInt64Value ¶
GetInt64Value function to get int value from record for given key
func GetIntValue ¶
GetIntValue function to get int value from record for given key
func GetSingleStringValue ¶
GetSingleStringValue function to get string value from record for given key
func GetSorted ¶
func GetSorted(dbname, collname string, spec map[string]any, skeys []string, sortOrder, idx, limit int) []map[string]any
GetSorted records from MongoDB sorted by given key with specific order
func GetStringValue ¶
GetStringValue function to get string value from record for given key
func InsertRecord ¶ added in v0.3.2
InsertRecord insert record with given spec to MongoDB
Types ¶
type Connection ¶
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 MongoDB ¶ added in v0.5.9
type MongoDB struct { }
MongoDB represents MongoDB interface with MongoDB backend
func (*MongoDB) Count ¶ added in v0.5.9
Count returns total number of records within database/collection and given spec
func (*MongoDB) Get ¶ added in v0.5.9
func (d *MongoDB) Get(dbname, collname string, spec map[string]any, idx, limit int) []map[string]any
Get fetches data from underlying database/collection
func (*MongoDB) GetSorted ¶ added in v0.5.9
func (d *MongoDB) GetSorted(dbname, collname string, spec map[string]any, skeys []string, sortOrder, idx, limit int) []map[string]any
GetSorted returns sorted records from given database/collection using provided spec, sorted keys, order and limits
func (*MongoDB) InsertRecord ¶ added in v0.5.9
InsertRecord inserts single record into given database/collection
func (*MongoDB) Remove ¶ added in v0.5.9
Remove deletes records in given database/collection using given spec