Documentation ¶
Index ¶
- func Aggregate(db *mongo.Database, model Model, extra *AggregateOpts) ([]interface{}, error)
- func ConvertID(id string) primitive.ObjectID
- func ConvertIDs(ids []string) []primitive.ObjectID
- func CountDocs(db *mongo.Database, model Model, query bson.M) int64
- func DateQuery(start, end time.Time) bson.M
- func DeleteMany(db *mongo.Database, model Model, query bson.M) bool
- func DeleteOne(db *mongo.Database, model Model, query bson.M) bool
- func EmptyMongoID() primitive.ObjectID
- func FindAll(db *mongo.Database, model Model, query bson.M, queryOpts *FindOptions) []interface{}
- func FindByID(coll *mongo.Collection, id string) *mongo.SingleResult
- func GetCacheKey(model Model, id string) string
- func InsertMany(db *mongo.Database, model Model, docs []interface{}) ([]interface{}, error)
- func NewMongoID() primitive.ObjectID
- func Query(db *mongo.Database, model Model, query bson.M, queryOpts *FindOptions) (*mongo.Cursor, error)
- func Save(db *mongo.Database, cacheClient *cache.MultiClient, model Model, id string) error
- func ToJSON(m Model) string
- func UpdateMany(db *mongo.Database, model Model, query, updateObj bson.M) error
- type AggregateOpts
- type FindOptions
- type Model
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Aggregate ¶
func Aggregate(db *mongo.Database, model Model, extra *AggregateOpts) ([]interface{}, error)
Aggregate method will aggregate the collection and return the results accordingly
func ConvertIDs ¶
ConvertIDs method will try to convert given slice to BSON Object ID slice
func DateQuery ¶
DateQuery will return the bson representation to query daterange between 2 time intervals
func DeleteMany ¶
DeleteMany method will delete multiple documents based on the filter
func EmptyMongoID ¶
EmptyMongoID method will return an objectID which is empty
func FindByID ¶
func FindByID(coll *mongo.Collection, id string) *mongo.SingleResult
FindByID method will try to find the document in collection with given id
func GetCacheKey ¶
GetCacheKey method returns the cache key for model with id
func InsertMany ¶
InsertMany method will insert documents in bulk inside the collection
func NewMongoID ¶
NewMongoID method will return a new BSON Objec ID
func Query ¶
func Query(db *mongo.Database, model Model, query bson.M, queryOpts *FindOptions) (*mongo.Cursor, error)
Query method will return cursor to the database
Types ¶
type AggregateOpts ¶
AggregateOpts method is used for holding options while doing aggregation
type FindOptions ¶
type FindOptions struct {
Sort, Hint interface{}
Projection interface{}
Limit, Skip *int64
BatchSize *int32
Timeout time.Duration
}
FindOptions struct will contain the additional find information
type Model ¶
type Model interface { New() Model Table() string IsEmpty() bool FindByID(db *mongo.Database, id string) Model ClearCacheData(cacheClient *cache.MultiClient) }
Model interface is a generic type for all the models
func CacheFirst ¶
CacheFirst method will try to find the object with given id in cache else it will query the db and save the result in cache
func FindOneWithOpts ¶
FindOneWithOpts method will try to find the object based on the query and options