Documentation ¶
Index ¶
- type IMongoData
- type MongoConfig
- type MongoSession
- func (m *MongoSession) Cleanup()
- func (m *MongoSession) DeleteSingle(col *mongo.Collection, id interface{}) error
- func (m *MongoSession) DeleteSingleContext(ctx context.Context, col *mongo.Collection, id interface{}) error
- func (m *MongoSession) GetColl(collname string) *mongo.Collection
- func (m *MongoSession) InsertBulk(col *mongo.Collection, data ...interface{}) error
- func (m *MongoSession) InsertBulkContext(ctx context.Context, col *mongo.Collection, data ...interface{}) error
- func (m *MongoSession) SaveSingle(col *mongo.Collection, data IMongoData) error
- func (m *MongoSession) SaveSingleContext(ctx context.Context, col *mongo.Collection, data IMongoData) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IMongoData ¶
type IMongoData interface {
GetID() interface{}
}
IMongoData is interface must be implemented by all models that need to save in MongoDB
type MongoConfig ¶
type MongoConfig struct { Host string Port int DbName string User string Pwd string ConnTimeout int // in seconds }
MongoConfig is config for mongodb connection
type MongoSession ¶
MongoSession holds session for mongodb connection
func InitSession ¶
func InitSession(config MongoConfig) *MongoSession
InitSession initialize mongodb session
func (*MongoSession) Cleanup ¶
func (m *MongoSession) Cleanup()
Cleanup closes existing mongodb session
func (*MongoSession) DeleteSingle ¶
func (m *MongoSession) DeleteSingle(col *mongo.Collection, id interface{}) error
DeleteSingle removes single document by ID
func (*MongoSession) DeleteSingleContext ¶
func (m *MongoSession) DeleteSingleContext(ctx context.Context, col *mongo.Collection, id interface{}) error
DeleteSingleContext removes single document by ID
func (*MongoSession) GetColl ¶
func (m *MongoSession) GetColl(collname string) *mongo.Collection
GetColl gives collection as specified
func (*MongoSession) InsertBulk ¶
func (m *MongoSession) InsertBulk(col *mongo.Collection, data ...interface{}) error
InsertBulk inserts multiple documents at once, if document already exist, error will be raised
func (*MongoSession) InsertBulkContext ¶
func (m *MongoSession) InsertBulkContext(ctx context.Context, col *mongo.Collection, data ...interface{}) error
InsertBulkContext inserts multiple documents at once, if document already exist, error will be raised
func (*MongoSession) SaveSingle ¶
func (m *MongoSession) SaveSingle(col *mongo.Collection, data IMongoData) error
SaveSingle insert or update single document by ID
func (*MongoSession) SaveSingleContext ¶
func (m *MongoSession) SaveSingleContext(ctx context.Context, col *mongo.Collection, data IMongoData) error
SaveSingleContext insert or update single document by ID