mongo

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertIdsToOids

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

ConvertIdsToOids converts a slice of documents to a slice of strings with the _id field converted to an $oid

func GetIDFromDocument

func GetIDFromDocument(document map[string]interface{}) (primitive.ObjectID, error)

GetIDFromDocument returns the _id field of a document as a primitive.ObjectID

func GetIDFromJSON

func GetIDFromJSON(jsonString string) (primitive.ObjectID, error)

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

func IndientJSON

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

IndientJSON indents a JSON string and returns a a buffer

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 StringifyDocument

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

StringifyDocument converts a map to a JSON 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
}

type DBsWithCollections

type DBsWithCollections struct {
	DB          string
	Collections []string
}

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, collection string) error

func (*Dao) DeleteCollection

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

func (*Dao) DeleteDocument

func (d *Dao) DeleteDocument(ctx context.Context, db string, collection string, id primitive.ObjectID) error

func (*Dao) ForceClose

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

func (*Dao) GetDocument

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

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, collection 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, db string, collection string, filter primitive.M, page, limit int64) ([]primitive.M, int64, error)

func (*Dao) UpdateDocument

func (d *Dao) UpdateDocument(ctx context.Context, db string, collection string, id primitive.ObjectID, document primitive.M) error

type Filter

type Filter struct {
	Key   string
	Value string
}

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"`
}

Jump to

Keyboard shortcuts

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