Documentation ¶
Index ¶
- func IsErrNoDocuments(err error) bool
- type DefaultMongoClient
- func (m *DefaultMongoClient) Aggregate(ctx context.Context, filters []interface{}, decoder interface{}) error
- func (m *DefaultMongoClient) DeleteOne(ctx context.Context, filter interface{}) error
- func (m *DefaultMongoClient) Find(ctx context.Context, queryBuilder query.QueryBuilder, decoder interface{}) error
- func (m *DefaultMongoClient) FindOne(ctx context.Context, queryBuilder query.QueryBuilder, decoder interface{}) error
- func (m *DefaultMongoClient) InsertOne(ctx context.Context, filter interface{}) (string, error)
- func (m *DefaultMongoClient) ReplaceOne(ctx context.Context, queryBuilder query.QueryBuilder, payload interface{}) error
- func (m *DefaultMongoClient) SetCollection(collection string)
- func (m *DefaultMongoClient) UpdateOne(ctx context.Context, filter interface{}, payload interface{}) error
- type DefaultMongoConfig
- type MongoClient
- type MongoConfig
- type ObjectID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsErrNoDocuments ¶ added in v1.24.0
IsErrNoDocuments checks if the error is actually the mongo.ErrNoDocuments
Types ¶
type DefaultMongoClient ¶
type DefaultMongoClient struct {
// contains filtered or unexported fields
}
DefaultMongoClient defines the default and basic handler to manage actions
with Mongo database
func (*DefaultMongoClient) Aggregate ¶
func (m *DefaultMongoClient) Aggregate( ctx context.Context, filters []interface{}, decoder interface{}, ) error
Aggregate executes an aggregate command
func (*DefaultMongoClient) DeleteOne ¶
func (m *DefaultMongoClient) DeleteOne( ctx context.Context, filter interface{}, ) error
DeleteOne deletes a single record in database
func (*DefaultMongoClient) Find ¶
func (m *DefaultMongoClient) Find( ctx context.Context, queryBuilder query.QueryBuilder, decoder interface{}, ) error
Find returns multiple records from the database
func (*DefaultMongoClient) FindOne ¶
func (m *DefaultMongoClient) FindOne( ctx context.Context, queryBuilder query.QueryBuilder, decoder interface{}, ) error
FindOne fetches a single record in database
func (*DefaultMongoClient) InsertOne ¶
func (m *DefaultMongoClient) InsertOne( ctx context.Context, filter interface{}, ) (string, error)
InsertOne stores a single record in database
func (*DefaultMongoClient) ReplaceOne ¶
func (m *DefaultMongoClient) ReplaceOne( ctx context.Context, queryBuilder query.QueryBuilder, payload interface{}, ) error
ReplaceOne replaces an entire record in database
func (*DefaultMongoClient) SetCollection ¶
func (m *DefaultMongoClient) SetCollection(collection string)
SetCollection sets the name of the collection
where actions will be performed
type DefaultMongoConfig ¶
type DefaultMongoConfig struct { DBName string // contains filtered or unexported fields }
DefaultMongoConfig defines the default and basic configuration to manage actions
with Mongo database
func (DefaultMongoConfig) GetConnUrl ¶
func (mc DefaultMongoConfig) GetConnUrl() string
GetConnUrl returns the URL of the database
func (DefaultMongoConfig) GetDBName ¶
func (mc DefaultMongoConfig) GetDBName() string
GetDBName returns the name of the DB
type MongoClient ¶
type MongoClient interface { // SetCollection sets the name of the collection // where actions will be performed SetCollection(string) // Aggregate executes an aggregate command Aggregate( ctx context.Context, filters []interface{}, decoder interface{}, ) error // Find returns multiple records from the database Find( ctx context.Context, queryBuilder query.QueryBuilder, decoder interface{}, ) error // FindOne fetches a single record in database FindOne( ctx context.Context, queryBuilder query.QueryBuilder, decoder interface{}, ) error // InsertOne stores a single record in database // and returns the id of the stored record InsertOne( ctx context.Context, filter interface{}, ) (string, error) // UpdateOne updates a single record in database UpdateOne( ctx context.Context, filter interface{}, payload interface{}, ) error // ReplaceOne replaces an entire record in database ReplaceOne( ctx context.Context, queryBuilder query.QueryBuilder, payload interface{}, ) error // DeleteOne deletes a single record in database DeleteOne( ctx context.Context, filter interface{}, ) error }
MongoClient defines a handler to manage actions with Mongo database
func NewDefaultMongoClient ¶
func NewDefaultMongoClient( mongoConfig MongoConfig, collection string, ) (MongoClient, error)
NewDefaultMongoClient returns an instance of MongoClient
type MongoConfig ¶
type MongoConfig interface { // GetConnUrl returns the URL of the database GetConnUrl() string // GetDBName returns the name of the DB GetDBName() string }
MongoConfig defines all data required to connect with a Mongo database
func NewDefaultMongoConfig ¶
func NewDefaultMongoConfig( connUrl string, DBName string, ) MongoConfig
NewDefaultMongoConfig creates an instance of MongoConfig
type ObjectID ¶ added in v1.23.0
ObjectID is a wrapper for the original primitive.ObjectID
func NewObjectID ¶ added in v1.23.0
func NewObjectID() *ObjectID
NewObjectID generates a new ObjectID.
func NewObjectIDFromHex ¶ added in v1.23.0
ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a valid ObjectID.