mongo

package
Version: v0.0.0-...-d841f61 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DB                                  = "canopsis"
	ConfigurationMongoCollection        = "configuration"
	RightsMongoCollection               = "default_rights"
	SessionMongoCollection              = "session"
	SessionStatsMongoCollection         = "default_session"
	AlarmMongoCollection                = "periodical_alarm"
	EntityMongoCollection               = "default_entities"
	PbehaviorMongoCollection            = "pbehavior"
	PbehaviorTypeMongoCollection        = "pbehavior_type"
	PbehaviorReasonMongoCollection      = "pbehavior_reason"
	PbehaviorExceptionMongoCollection   = "pbehavior_exception"
	ScenarioMongoCollection             = "action_scenario"
	FileMongoCollection                 = "files"
	InstructionMongoCollection          = "instruction"
	InstructionExecutionMongoCollection = "instruction_execution"
	InstructionRatingMongoCollection    = "instruction_rating"
	JobConfigMongoCollection            = "job_config"
	JobMongoCollection                  = "job"
	JobHistoryMongoCollection           = "job_history"
	MetaAlarmRulesMongoCollection       = "meta_alarm_rules"
	HeartbeatMongoCollection            = "heartbeat"
	IdleRuleMongoCollection             = "idle_rule"
	ExportTaskMongoCollection           = "export_task"
	ActionLogMongoCollection            = "action_log"
	EventFilterRulesMongoCollection     = "eventfilter"
	DynamicInfosRulesMongoCollection    = "dynamic_infos"
	WebhookMongoCollection              = "webhooks"
	EntityCategoryMongoCollection       = "entity_category"
	ImportJobMongoCollection            = "default_importgraph"
	JunitTestSuiteMongoCollection       = "junit_test_suite"
	JunitTestCaseMediaMongoCollection   = "junit_test_case_media"
	ViewMongoCollection                 = "views"
	ViewGroupMongoCollection            = "viewgroups"
	PlaylistMongoCollection             = "view_playlist"
	StateSettingsMongoCollection        = "state_settings"
	BroadcastMessageMongoCollection     = "broadcast_message"
	AssociativeTableCollection          = "default_associativetable"
)
View Source
const (
	EnvURL = "CPS_MONGO_URL"
)

Variables

This section is empty.

Functions

func IsConnectionError

func IsConnectionError(err error) bool

Types

type Config

type Config struct {
	// Indexes structure is [collectionName][indexName]indexConfig
	Indexes map[string]map[string]IndexConfig `yaml:"indexes"`
}

Config represents format of config file.

type Cursor

type Cursor interface {
	All(ctx context.Context, results interface{}) error
	Next(ctx context.Context) bool
	Close(ctx context.Context) error
	Decode(val interface{}) error
	Err() error
}

type DbClient

type DbClient interface {
	Collection(string) DbCollection
}

DbClient connected MongoDB client settings

func NewClient

func NewClient(retryCount int, minRetryTimeout time.Duration) (DbClient, error)

NewClient creates a new connection to the MongoDB database. It uses EnvURL as configuration source.

type DbCollection

type DbCollection interface {
	Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (Cursor, error)
	BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)
	CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)
	DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (int64, error)
	DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (int64, error)
	Distinct(ctx context.Context, fieldName string, filter interface{},
		opts ...*options.DistinctOptions) ([]interface{}, error)
	Drop(ctx context.Context) error
	Find(ctx context.Context, filter interface{},
		opts ...*options.FindOptions) (Cursor, error)
	FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) SingleResultHelper
	FindOneAndDelete(ctx context.Context, filter interface{},
		opts ...*options.FindOneAndDeleteOptions) SingleResultHelper
	FindOneAndReplace(ctx context.Context, filter interface{}, replacement interface{},
		opts ...*options.FindOneAndReplaceOptions) SingleResultHelper
	FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{},
		opts ...*options.FindOneAndUpdateOptions) SingleResultHelper
	Indexes() mongo.IndexView
	InsertOne(ctx context.Context, document interface{},
		opts ...*options.InsertOneOptions) (interface{}, error)
	InsertMany(ctx context.Context, documents []interface{},
		opts ...*options.InsertManyOptions) ([]interface{}, error)
	ReplaceOne(ctx context.Context, filter interface{},
		replacement interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)
	UpdateMany(ctx context.Context, filter interface{}, update interface{},
		opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	UpdateOne(ctx context.Context, filter interface{}, update interface{},
		opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
}

type IndexConfig

type IndexConfig struct {
	Keys    map[string]int         `yaml:"keys"`
	Options map[string]interface{} `yaml:"options"`
}

IndexConfig represent format of index in config file.

type IndexService

type IndexService interface {
	Create() error
}

IndexService is used to implement mongo indexes creations. Base implementation uses config configDir as source of index options.

func NewIndexService

func NewIndexService(
	dbClient DbClient,
	configDir string,
	logger *zerolog.Logger,
) IndexService

NewIndexService creates index service.

type SingleResultHelper

type SingleResultHelper interface {
	Decode(v interface{}) error
	DecodeBytes() (bson.Raw, error)
	Err() error
}

Jump to

Keyboard shortcuts

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