mongo

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 25 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSchemaIntrospection = xerror.Unavailable(xerror.SchemaMetadata)

ErrSchemaIntrospection indicates that schema introspection failed.

Functions

func FieldTypeStrings

func FieldTypeStrings() []string

FieldTypeStrings returns a slice of all String values of the enum

func OperationStrings

func OperationStrings() []string

OperationStrings returns a slice of all String values of the enum

Types

type Collection

type Collection struct {
	// Name is the name of the collection.
	Name string

	// Fields is a list of fields discovered by sampling documents in the collection.
	Fields []Field

	// DocumentCount is the total number of documents in the collection (optional).
	DocumentCount int64
}

Collection represents a single collection in the MongoDB database.

type CollectionMetadataObserver

type CollectionMetadataObserver struct {
	Host         string `json:"host"`
	Port         uint16 `json:"port"`
	Database     string `json:"database"`
	Collection   string `json:"collection"`
	AuthDatabase string `json:"auth_database,omitempty"`
}

CollectionMetadataObserver uses a name-filtered catalog command, never records.

func (CollectionMetadataObserver) AssessMetadata

func (CollectionMetadataObserver) Description

func (o CollectionMetadataObserver) Description() string

func (CollectionMetadataObserver) MatchesResource

func (o CollectionMetadataObserver) MatchesResource(config, operation json.RawMessage, source bool) bool

func (CollectionMetadataObserver) Plan

func (CollectionMetadataObserver) ReadMetadata

func (o CollectionMetadataObserver) ReadMetadata(ctx context.Context, transport proofevidence.MetadataIO, credential []byte, limits proofevidence.Limits) (metadataJSON json.RawMessage, rows int64, outcome proofevidence.Outcome)

type CollectionMetadataSnapshot

type CollectionMetadataSnapshot struct {
	Database   string `json:"database"`
	Collection string `json:"collection"`
	Type       string `json:"type"`
}

type Config

type Config struct {
	Host              string `json:"host"                      validate:"required"`
	Port              int    `json:"port"                      validate:"required,min=1,max=65535"`
	Database          string `json:"database"                  validate:"required"`
	AuthDatabase      string `json:"auth_database,omitempty"   validate:"omitempty"`
	ConnectTimeout    int    `json:"connect_timeout,omitempty"`
	AllowPrivateHosts bool   `json:"allow_private_hosts,omitempty"`
}

Config holds configuration for MongoDB connections.

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

Connector connects to MongoDB databases.

func New

func New(ctx context.Context, config Config, creds Credentials) (*Connector, error)

New creates a new MongoDB connector with the provided configuration and credentials.

func (*Connector) Close

func (c *Connector) Close() error

Close disconnects from MongoDB and releases resources.

func (*Connector) Execute

func (c *Connector) Execute(
	ctx context.Context,
	queryData json.RawMessage,
	params map[string]types.TypedParam,
	limits ...types.ExecutionLimits,
) (*result.ExecutionResult, error)

Execute executes a MongoDB operation described by queryData with the provided parameters.

queryData must be a JSON object with at least "collection" and "operation" fields. Supported operations:

  • Read: OperationFind, OperationAggregate, OperationCountDocuments
  • Write: OperationInsertOne, OperationInsertMany, OperationUpdateOne, OperationDeleteOne, OperationUpdateMany, OperationDeleteMany

params are merged into the filter for read operations and write operations that use filters. Write operations require additional fields (document for insertOne, update for updateOne/updateMany).

func (*Connector) IntrospectSchema

func (c *Connector) IntrospectSchema(ctx context.Context) (*Schema, error)

IntrospectSchema retrieves the MongoDB schema by sampling documents from each collection.

func (*Connector) TestConnection

func (c *Connector) TestConnection(ctx context.Context) error

TestConnection verifies that a connection to MongoDB can be established.

type Credentials

type Credentials struct {
	Username string `json:"username" validate:"required"`
	Password string `json:"password" validate:"required"`
}

Credentials holds MongoDB authentication values.

type Field

type Field struct {
	// Name is the field name (key in the document).
	Name string

	// Type is the inferred BSON type.
	Type FieldType

	// Nullable indicates whether the field was missing in some sampled documents.
	Nullable bool
}

Field represents a field discovered in sampled documents.

type FieldType

type FieldType int

FieldType represents the inferred type of a MongoDB field from BSON data.

const (
	FieldTypeUnknown   FieldType = iota // unknown
	FieldTypeStr                        // string
	FieldTypeInt                        // int
	FieldTypeDouble                     // double
	FieldTypeBoolean                    // boolean
	FieldTypeObjectID                   // objectId
	FieldTypeDate                       // date
	FieldTypeTimestamp                  // timestamp
	FieldTypeObject                     // object
	FieldTypeArray                      // array
	FieldTypeBinary                     // binary
	FieldTypeDecimal                    // decimal
	FieldTypeRegex                      // regex
	FieldTypeNull                       // null
	FieldTypeMixed                      // mixed
)

func FieldTypeString

func FieldTypeString(s string) (FieldType, error)

FieldTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func FieldTypeValues

func FieldTypeValues() []FieldType

FieldTypeValues returns all values of the enum

func (FieldType) IsAFieldType

func (i FieldType) IsAFieldType() bool

IsAFieldType returns "true" if the value is listed in the enum definition. "false" otherwise

func (FieldType) MarshalText

func (i FieldType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for FieldType

func (FieldType) String

func (i FieldType) String() string

func (*FieldType) UnmarshalText

func (i *FieldType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for FieldType

type Operation

type Operation int

Operation represents a MongoDB operation type.

const (
	OperationUnknown Operation = iota // unknown

	// Read operations
	OperationFind           // find
	OperationAggregate      // aggregate
	OperationCountDocuments // count_documents

	// Write operations
	OperationInsertOne  // insert_one
	OperationInsertMany // insert_many
	OperationUpdateOne  // update_one
	OperationDeleteOne  // delete_one
	OperationUpdateMany // update_many
	OperationDeleteMany // delete_many
)

func OperationString

func OperationString(s string) (Operation, error)

OperationString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func OperationValues

func OperationValues() []Operation

OperationValues returns all values of the enum

func (Operation) IsAOperation

func (i Operation) IsAOperation() bool

IsAOperation returns "true" if the value is listed in the enum definition. "false" otherwise

func (Operation) MarshalText

func (i Operation) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Operation

func (Operation) String

func (i Operation) String() string

func (*Operation) UnmarshalText

func (i *Operation) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Operation

type Schema

type Schema struct {
	// Collections is a list of collections in the data source.
	Collections []Collection
}

Schema represents the MongoDB schema of a data source.

type SchemaIntrospector

type SchemaIntrospector interface {
	// IntrospectSchema retrieves the MongoDB schema (collections, fields, types).
	// Samples documents to infer field types since MongoDB is schemaless.
	IntrospectSchema(ctx context.Context) (*Schema, error)
}

SchemaIntrospector retrieves MongoDB schema metadata.

Jump to

Keyboard shortcuts

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