mongodb

package
v0.0.0-...-bcdb799 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChaosInfraCollection = iota
	ChaosExperimentCollection
	ChaosExperimentRunsCollection
	ChaosHubCollection
	ImageRegistryCollection
	ServerConfigCollection
	GitOpsCollection
	UserCollection
	ProjectCollection
	EnvironmentCollection
	ChaosProbeCollection
)

Enum for Database collections

Variables

View Source
var (
	Client      MongoInterface = &MongoClient{}
	MgoClient   *mongo.Client
	Collections = map[int]string{
		ChaosInfraCollection:          "chaosInfrastructures",
		ChaosExperimentCollection:     "chaosExperiments",
		ChaosExperimentRunsCollection: "chaosExperimentRuns",
		ChaosProbeCollection:          "chaosProbes",
		ChaosHubCollection:            "chaosHubs",
		ImageRegistryCollection:       "imageRegistry",
		ServerConfigCollection:        "serverConfig",
		GitOpsCollection:              "gitops",
		UserCollection:                "user",
		ProjectCollection:             "project",
		EnvironmentCollection:         "environment",
	}

	DbName            = "litmus"
	ConnectionTimeout = 20 * time.Second
)

Functions

func MongoConnection

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

Types

type Audit

type Audit struct {
	UpdatedAt int64              `bson:"updated_at"`
	CreatedAt int64              `bson:"created_at"`
	CreatedBy UserDetailResponse `bson:"created_by" json:"createdBy"`
	UpdatedBy UserDetailResponse `bson:"updated_by" json:"updatedBy"`
	IsRemoved bool               `bson:"is_removed"`
}

type GetCollectionInterface

type GetCollectionInterface interface {
	// contains filtered or unexported methods
}
var GetCollectionClient GetCollectionInterface = &GetCollectionStruct{}

type GetCollectionStruct

type GetCollectionStruct struct{}

type MongoClient

type MongoClient struct {
	Database                      *mongo.Database
	ChaosInfraCollection          *mongo.Collection
	ChaosExperimentCollection     *mongo.Collection
	ChaosExperimentRunsCollection *mongo.Collection
	ChaosHubCollection            *mongo.Collection
	ChaosServerConfigCollection   *mongo.Collection
	ImageRegistryCollection       *mongo.Collection
	ServerConfigCollection        *mongo.Collection
	GitOpsCollection              *mongo.Collection
	UserCollection                *mongo.Collection
	ProjectCollection             *mongo.Collection
	EnvironmentCollection         *mongo.Collection
	ChaosProbeCollection          *mongo.Collection
}

MongoClient structure contains all the Database collections and the instance of the Database

func (*MongoClient) Initialize

func (m *MongoClient) Initialize(client *mongo.Client) *MongoClient

Initialize initializes database connection

type MongoInterface

type MongoInterface interface {
	Initialize(client *mongo.Client) *MongoClient
	// 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
}

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, opts ...*options.FindOptions) (*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

func (*MongoOperations) WatchEvents

func (m *MongoOperations) WatchEvents(ctx context.Context, client *mongo.Client, collectionType int, pipeline mongo.Pipeline, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)

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, opts ...*options.FindOptions) (*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)
	GetCollection(collectionType int) (*mongo.Collection, error)
	ListCollection(ctx context.Context, mclient *mongo.Client) ([]string, error)
	ListDataBase(ctx context.Context, mclient *mongo.Client) ([]string, error)
	WatchEvents(ctx context.Context, client *mongo.Client, collectionType int, pipeline mongo.Pipeline, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)
}
var (
	// Operator contains all the CRUD operations of the mongo database
	Operator MongoOperator = &MongoOperations{}
)

type ResourceDetails

type ResourceDetails struct {
	Name        string   `bson:"name"`
	Description string   `bson:"description"`
	Tags        []string `bson:"tags"`
}

type UserDetailResponse

type UserDetailResponse struct {
	UserID   string `bson:"user_id" json:"userID"`
	Username string `bson:"username" json:"username"`
	Email    string `bson:"email" json:"email"`
}

Directories

Path Synopsis
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