Documentation ¶
Index ¶
- Constants
- Variables
- func MongoConnection() (*mongo.Client, error)
- type GetCollectionInterface
- type GetCollectionStruct
- type MongoClient
- type MongoInterface
- type MongoOperations
- func (m *MongoOperations) Aggregate(ctx context.Context, collectionType int, pipeline interface{}, ...) (*mongo.Cursor, error)
- func (m *MongoOperations) CountDocuments(ctx context.Context, collectionType int, query bson.D, ...) (int64, error)
- func (m *MongoOperations) Create(ctx context.Context, collectionType int, document interface{}) error
- func (m *MongoOperations) CreateMany(ctx context.Context, collectionType int, documents []interface{}) error
- func (m *MongoOperations) Delete(ctx context.Context, collectionType int, query bson.D, ...) (*mongo.DeleteResult, error)
- func (m *MongoOperations) Get(ctx context.Context, collectionType int, query bson.D) (*mongo.SingleResult, error)
- func (m *MongoOperations) GetCollection(collectionType int) (*mongo.Collection, error)
- func (m *MongoOperations) List(ctx context.Context, collectionType int, query bson.D) (*mongo.Cursor, error)
- func (m *MongoOperations) ListCollection(ctx context.Context, mclient *mongo.Client) ([]string, error)
- func (m *MongoOperations) ListDataBase(ctx context.Context, mclient *mongo.Client) ([]string, error)
- func (m *MongoOperations) Replace(ctx context.Context, collectionType int, query bson.D, replacement interface{}) (*mongo.UpdateResult, error)
- func (m *MongoOperations) Update(ctx context.Context, collectionType int, query, update bson.D, ...) (*mongo.UpdateResult, error)
- func (m *MongoOperations) UpdateMany(ctx context.Context, collectionType int, query, update bson.D, ...) (*mongo.UpdateResult, error)
- type MongoOperator
Constants ¶
const ( ClusterCollection = iota UserCollection ProjectCollection WorkflowCollection WorkflowTemplateCollection GitOpsCollection ChaosHubCollection DataSourceCollection PanelCollection DashboardCollection ImageRegistryCollection ServerConfigCollection )
Enum for Database collections
Variables ¶
var (
ConnectionTimeout = 20 * time.Second
)
Functions ¶
func MongoConnection ¶
Types ¶
type GetCollectionInterface ¶
type GetCollectionInterface interface {
// contains filtered or unexported methods
}
type GetCollectionStruct ¶
type GetCollectionStruct struct{}
type MongoClient ¶
type MongoClient struct { Database *mongo.Database ClusterCollection *mongo.Collection UserCollection *mongo.Collection ProjectCollection *mongo.Collection WorkflowCollection *mongo.Collection WorkflowTemplateCollection *mongo.Collection GitOpsCollection *mongo.Collection ChaosHubCollection *mongo.Collection DataSourceCollection *mongo.Collection PanelCollection *mongo.Collection DashboardCollection *mongo.Collection ImageRegistryCollection *mongo.Collection ServerConfigCollection *mongo.Collection }
MongoClient structure contains all the Database collections and the instance of the Database
func Initialize ¶
func Initialize(client *mongo.Client) *MongoClient
Initialize initializes database connection
type MongoInterface ¶
type MongoInterface interface {
// contains filtered or unexported methods
}
MongoInterface requires a MongoClient that implements the Initialize method to create the Mongo DB client and a initAllCollection method to initialize all DB Collections
type MongoOperations ¶
type MongoOperations struct { MongoClient *MongoClient // contains filtered or unexported fields }
func NewMongoOperations ¶
func NewMongoOperations(mongoClient *MongoClient) *MongoOperations
func (*MongoOperations) Aggregate ¶
func (m *MongoOperations) Aggregate(ctx context.Context, collectionType int, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)
func (*MongoOperations) CountDocuments ¶
func (m *MongoOperations) CountDocuments(ctx context.Context, collectionType int, query bson.D, opts ...*options.CountOptions) (int64, error)
CountDocuments returns the number of documents in the collection that matches a query
func (*MongoOperations) Create ¶
func (m *MongoOperations) Create(ctx context.Context, collectionType int, document interface{}) error
Create puts a document in the database
func (*MongoOperations) CreateMany ¶
func (m *MongoOperations) CreateMany(ctx context.Context, collectionType int, documents []interface{}) error
CreateMany puts an array of documents in the database
func (*MongoOperations) Delete ¶
func (m *MongoOperations) Delete(ctx context.Context, collectionType int, query bson.D, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
Delete removes a document from the database based on a query
func (*MongoOperations) Get ¶
func (m *MongoOperations) Get(ctx context.Context, collectionType int, query bson.D) (*mongo.SingleResult, error)
Get fetches a document from the database based on a query
func (*MongoOperations) GetCollection ¶
func (m *MongoOperations) GetCollection(collectionType int) (*mongo.Collection, error)
GetCollection fetches the correct collection based on the collection type
func (*MongoOperations) List ¶
func (m *MongoOperations) List(ctx context.Context, collectionType int, query bson.D) (*mongo.Cursor, error)
List fetches a list of documents from the database based on a query
func (*MongoOperations) ListCollection ¶
func (*MongoOperations) ListDataBase ¶
func (*MongoOperations) Replace ¶
func (m *MongoOperations) Replace(ctx context.Context, collectionType int, query bson.D, replacement interface{}) (*mongo.UpdateResult, error)
Replace changes a document with a new one in the database based on a query
func (*MongoOperations) Update ¶
func (m *MongoOperations) Update(ctx context.Context, collectionType int, query, update bson.D, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
Update updates a document in the database based on a query
func (*MongoOperations) UpdateMany ¶
func (m *MongoOperations) UpdateMany(ctx context.Context, collectionType int, query, update bson.D, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
UpdateMany updates multiple documents in the database based on a query
type MongoOperator ¶
type MongoOperator interface { Create(ctx context.Context, collectionType int, document interface{}) error CreateMany(ctx context.Context, collectionType int, documents []interface{}) error Get(ctx context.Context, collectionType int, query bson.D) (*mongo.SingleResult, error) List(ctx context.Context, collectionType int, query bson.D) (*mongo.Cursor, error) Update(ctx context.Context, collectionType int, query, update bson.D, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) UpdateMany(ctx context.Context, collectionType int, query, update bson.D, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) Replace(ctx context.Context, collectionType int, query bson.D, replacement interface{}) (*mongo.UpdateResult, error) Delete(ctx context.Context, collectionType int, query bson.D, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error) CountDocuments(ctx context.Context, collectionType int, query bson.D, opts ...*options.CountOptions) (int64, error) Aggregate(ctx context.Context, collectionType int, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error) ListCollection(ctx context.Context, mclient *mongo.Client) ([]string, error) ListDataBase(ctx context.Context, mclient *mongo.Client) ([]string, error) }