mango
From a database management tools for optifur services, mango grew to become its own tooling module for use with mongodb databases.
mgo helper functions
The goal of the lib is to be able to generate simple request and pigination for mgo based on an input struct.
One function to generate pagination data based on mgo tags of the struct
One function to generate filtering data based on mgo tags of the struct
filtering
Need to be able to filter, based on an input struct
- the tag define the field name/path of the mgo data
_id
, username
, friends.amount
, etc... (The same way mongo does)
- the tag should define the test opperator. It will be "fieldFromStruct OPERATOR fieldInDb" using mgo operators
- default filtering is a
$and
, can be set to $or
in function options
Tag format: mgo-filter:"fieldName,op:OPERATOR,omitempty"
with:
fieldName
the name of the field in mongo database, may be toto.titi
for field titi
inside toto
op
the operator to use for comparision, eg $eq
, $gt
, etc
omitempty
define the behaviour for empty/nil value. If omitempty
is set, empty value or nil value will be ignored, else empty values will be used when filtering
Tag format:
mgo-paging:"limit,default: 10"
mgo-paging:"offset"
// No default for offset, 0
mgo-paging:"sort,default: _id_"
// Any field
mgo-paging:"sort-revert,default: _id_"
// Any field
Nil pointer => use default value