mongodb

package
v0.0.0-...-d4d4b81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterCollection = iota
	UserCollection
	ProjectCollection
	WorkflowCollection
	WorkflowTemplateCollection
	GitOpsCollection
	ChaosHubCollection
	DataSourceCollection
	PanelCollection
	DashboardCollection
	ImageRegistryCollection
	ServerConfigCollection
)

Enum for Database collections

Variables

View Source
var (
	ConnectionTimeout = 20 * time.Second
)

Functions

func MongoConnection

func MongoConnection() (*mongo.Client, error)

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 (m *MongoOperations) ListCollection(ctx context.Context, mclient *mongo.Client) ([]string, error)

func (*MongoOperations) ListDataBase

func (m *MongoOperations) ListDataBase(ctx context.Context, mclient *mongo.Client) ([]string, error)

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)
}

Directories

Path Synopsis
model
mocks
Package mocks contains all the mocks for the mongo_operator.go file
Package mocks contains all the mocks for the mongo_operator.go file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL