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.Client, 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 BufferWriter
- 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 BufferWriter ¶
type BufferWriter struct { Docs []interface{} Table string Host string Count int MessageClient *messaging.Message Conn *mongo.Database }
BufferWriter struct holds the elements docs and ids till they are flushed to database either manually using a timed event or when the count of the resource exceeds a certain threshold value
func NewBufferWriter ¶
func NewBufferWriter() *BufferWriter
NewBufferWriter creates a writer object for all the subsequents calls
func (*BufferWriter) BulkInsert ¶
func (w *BufferWriter) BulkInsert(override bool)
BulkInsert checks the docs count and if the count exceeds the max buffer count then the documents are flushed to the database and all the counters are reset
func (*BufferWriter) Flush ¶
func (w *BufferWriter) Flush()
Flush manually flushes the data to database overriding the checks
func (*BufferWriter) InsertDocs ¶
func (w *BufferWriter) InsertDocs(d interface{})
InsertDocs method appends the click to the w.docs slice and increments the click count by creating a read write lock to handle concurrent writes to the same object
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 FindOne(db *mongo.Database, id string) Model ClearCacheData(cacheClient *cache.Client) }
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