mongo

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIDFromJSON

func GetIDFromJSON(jsonString string) (interface{}, error)

GetIDFromJSON returns the _id field of a JSON string as a primitive.ObjectID.

func IndentJson

func IndentJson(jsonString string) (bytes.Buffer, error)

IndentJson indents a JSON string and returns a a buffer

func ParseBsonDocument

func ParseBsonDocument(document map[string]interface{}) (string, error)

ParseBsonDocument converts a map to a JSON string

func ParseBsonDocuments

func ParseBsonDocuments(documents []primitive.M) ([]string, error)

ParseBsonDocuments converts a slice of documents to a slice of strings with mongo compatible JSON

func ParseJsonToBson

func ParseJsonToBson(jsonDoc string) (primitive.M, error)

ParseJsonToBson converts a JSON string to a primitive.M document

func ParseStringQuery

func ParseStringQuery(query string) (map[string]interface{}, error)

ParseStringQuery transforms a query string with ObjectID into a filter map compatible with MongoDB's BSON. If keys are not quoted, this function will quote them.

func StringifyId

func StringifyId(id interface{}) string

StringifyId converts the _id field of a document to a string

Types

type Client

type Client struct {
	Client *mongo.Client
	Config *config.MongoConfig
}

func NewClient

func NewClient(config *config.MongoConfig) *Client

func (*Client) Close

func (m *Client) Close(ctx context.Context)

func (*Client) Connect

func (m *Client) Connect() error

func (*Client) Ping

func (m *Client) Ping() error

type CollectionState

type CollectionState struct {
	Db     string
	Coll   string
	Page   int64
	Limit  int64
	Count  int64
	Sort   string
	Filter string
	// contains filtered or unexported fields
}

CollectionState is used to store the state of a collection and use it while rendering doesn't require fetching from the database

func NewCollectionState added in v0.1.20

func NewCollectionState(db, coll string) *CollectionState

func (*CollectionState) AppendDoc

func (c *CollectionState) AppendDoc(doc primitive.M)

func (*CollectionState) DeleteDoc

func (c *CollectionState) DeleteDoc(id interface{})

func (*CollectionState) GetAllDocs added in v0.1.4

func (c *CollectionState) GetAllDocs() []primitive.M

func (*CollectionState) GetDocById

func (c *CollectionState) GetDocById(id interface{}) primitive.M

func (*CollectionState) GetJsonDocById

func (c *CollectionState) GetJsonDocById(id interface{}) (string, error)

func (*CollectionState) PopulateDocs

func (c *CollectionState) PopulateDocs(docs []primitive.M)

func (*CollectionState) SetFilter added in v0.1.10

func (c *CollectionState) SetFilter(filter string)

func (*CollectionState) SetSort added in v0.1.10

func (c *CollectionState) SetSort(sort string)

func (*CollectionState) UpdateRawDoc

func (c *CollectionState) UpdateRawDoc(doc string) error

type DBsWithCollections

type DBsWithCollections struct {
	DB          string
	Collections []string
}

DBsWithCollections is a object used to store the database name and its collections

type Dao

type Dao struct {
	Config *config.MongoConfig
	// contains filtered or unexported fields
}

func NewDao

func NewDao(client *mongo.Client, config *config.MongoConfig) *Dao

func (*Dao) AddCollection

func (d *Dao) AddCollection(ctx context.Context, db string, coll string) error

func (*Dao) CreateIndex added in v0.1.9

func (d *Dao) CreateIndex(ctx context.Context, db, coll string, indexDef mongo.IndexModel) error

func (*Dao) DeleteCollection

func (d *Dao) DeleteCollection(ctx context.Context, db string, coll string) error

func (*Dao) DeleteDocument

func (d *Dao) DeleteDocument(ctx context.Context, db string, coll string, id interface{}) error

func (*Dao) DropIndex added in v0.1.9

func (d *Dao) DropIndex(ctx context.Context, db, coll, indexName string) error

func (*Dao) ForceClose

func (d *Dao) ForceClose(ctx context.Context) error

func (*Dao) GetDocument

func (d *Dao) GetDocument(ctx context.Context, db string, coll string, id primitive.ObjectID) (primitive.M, error)

func (*Dao) GetIndexes added in v0.1.5

func (d *Dao) GetIndexes(ctx context.Context, db string, coll string) ([]IndexInfo, error)

GetIndexes fetches the indexes for a given database and collection

func (*Dao) GetLiveSessions

func (d *Dao) GetLiveSessions(ctx context.Context) (int64, error)

func (*Dao) GetServerStatus

func (d *Dao) GetServerStatus(ctx context.Context) (*ServerStatus, error)

func (*Dao) InsetDocument

func (d *Dao) InsetDocument(ctx context.Context, db string, coll string, document primitive.M) (interface{}, error)

func (*Dao) ListDbsWithCollections

func (d *Dao) ListDbsWithCollections(ctx context.Context, nameRegex string) ([]DBsWithCollections, error)

func (*Dao) ListDocuments

func (d *Dao) ListDocuments(ctx context.Context, state *CollectionState, filter primitive.M, sort primitive.M) ([]primitive.M, int64, error)

func (*Dao) Ping

func (d *Dao) Ping(ctx context.Context) error

func (*Dao) RenameCollection added in v0.1.12

func (d *Dao) RenameCollection(ctx context.Context, db string, oldColl string, newColl string) error

func (*Dao) UpdateDocument

func (d *Dao) UpdateDocument(ctx context.Context, db string, coll string, id interface{}, originalDoc, document primitive.M) error

type IndexInfo added in v0.1.5

type IndexInfo struct {
	Name       string
	Definition bson.M
	Type       string
	Size       string
	Usage      string
	Properties []string
}

IndexInfo represents the combined information about an index from multiple commands

type MongoAutocomplete

type MongoAutocomplete struct {
	Operators []MongoKeyword
}

func NewMongoAutocomplete

func NewMongoAutocomplete() *MongoAutocomplete

func (*MongoAutocomplete) GetOperatorByDisplay

func (m *MongoAutocomplete) GetOperatorByDisplay(display string) *MongoKeyword

type MongoKeyword

type MongoKeyword struct {
	Display     string
	InsertText  string
	Description string
}

MongoKeyword represents single mongo keyword Display is displayed in autocomplete InsertText is inserted into input, use <$i> marker to mark position for cursor, if empty then cursor moves to the end of the text Description is displayed in autocomplete description

type ServerStatus

type ServerStatus struct {
	Ok             int32  `bson:"ok"`
	Version        string `bson:"version"`
	Uptime         int32  `bson:"uptime"`
	CurrentConns   int32  `bson:"connections.current"`
	AvailableConns int32  `bson:"connections.available"`
	OpCounters     struct {
		Insert int32 `bson:"insert"`
		Query  int32 `bson:"query"`
		Update int32 `bson:"update"`
		Delete int32 `bson:"delete"`
	} `bson:"opcounters"`
	Mem struct {
		Resident int32 `bson:"resident"`
		Virtual  int32 `bson:"virtual"`
	} `bson:"mem"`
	Repl struct {
		ReadOnly bool `bson:"readOnly"`
		IsMaster bool `bson:"ismaster"`
	} `bson:"repl"`
}

ServerStatus are the values chosen from the serverStatus command

type StateMap added in v0.1.4

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

StateMap persevere states when hopping between diffrent mongodb servers

func NewStateMap added in v0.1.4

func NewStateMap() *StateMap

func (*StateMap) AddHiddenColumn added in v0.1.20

func (sm *StateMap) AddHiddenColumn(db, coll, column string)

func (*StateMap) Get added in v0.1.4

func (sm *StateMap) Get(key string) (*CollectionState, bool)

func (*StateMap) GetHiddenColumns added in v0.1.20

func (sm *StateMap) GetHiddenColumns(db, coll string) []string

func (*StateMap) Key added in v0.1.4

func (sm *StateMap) Key(db, coll string) string

func (*StateMap) ResetHiddenColumns added in v0.1.20

func (sm *StateMap) ResetHiddenColumns(db, coll string)

func (*StateMap) Set added in v0.1.4

func (sm *StateMap) Set(key string, state *CollectionState)

Jump to

Keyboard shortcuts

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