mongo

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// PackageName is the package name.
	PackageName = "go-mongo"
	// DefaultHost is the default host for MongoDB servers.
	DefaultHost string = "localhost"
	// DefaultPort is the default port for mongod and mongos.
	DefaultPort int = 27017
	// DefaultTimeoutSecond is the default request timeout for MongoDB servers.
	DefaultTimeoutSecond = 5
)
View Source
const (
	Version = "v1.0.2"
)

Variables

View Source
var ErrQuery = errors.New("query error")
View Source
var ErrQueryNotSupported = errors.New("query not supported")

Functions

func NewNotSupported added in v0.9.1

func NewNotSupported(q *Query) error

func NewQueryError added in v0.9.1

func NewQueryError(q *Query) error

Types

type BaseCommandExecutor

type BaseCommandExecutor struct {
	UserCommandExecutor
	DatabaseCommandExecutor
}

BaseCommandExecutor is a complete hander for CommandExecutor.

func NewBaseCommandExecutor

func NewBaseCommandExecutor() *BaseCommandExecutor

NewBaseCommandExecutor returns a complete null executor for CommandExecutor.

func (*BaseCommandExecutor) Delete

func (executor *BaseCommandExecutor) Delete(conn *Conn, q *Query) (int32, error)

Delete hadles OP_DELETE and 'delete' query of OP_MSG.

func (*BaseCommandExecutor) ExecuteBuildInfo

func (executor *BaseCommandExecutor) ExecuteBuildInfo(cmd *Command) (bson.Document, error)

ExecuteBuildInfo returns statistics about the MongoDB build.

func (*BaseCommandExecutor) ExecuteCommand

func (executor *BaseCommandExecutor) ExecuteCommand(cmd *Command) (bson.Document, error)

ExecuteCommand handles query commands other than those explicitly specified above.

func (*BaseCommandExecutor) ExecuteGetLastError

func (executor *BaseCommandExecutor) ExecuteGetLastError(cmd *Command) (bson.Document, error)

ExecuteGetLastError returns statistics about the MongoDB build.

func (*BaseCommandExecutor) ExecuteIsMaster

func (executor *BaseCommandExecutor) ExecuteIsMaster(cmd *Command) (bson.Document, error)

ExecuteIsMaster returns information about this member’s role in the replica set, including whether it is the master.

func (*BaseCommandExecutor) Find

func (executor *BaseCommandExecutor) Find(conn *Conn, q *Query) ([]bson.Document, error)

Find hadles 'find' query of OP_MSG.

func (*BaseCommandExecutor) Insert

func (executor *BaseCommandExecutor) Insert(conn *Conn, q *Query) (int32, error)

Insert hadles OP_INSERT and 'insert' query of OP_MSG.

func (*BaseCommandExecutor) SetDatabaseCommandExecutor

func (executor *BaseCommandExecutor) SetDatabaseCommandExecutor(fn DatabaseCommandExecutor)

SetDatabaseCommandExecutor sets a command exector for database operation commands.

func (*BaseCommandExecutor) SetUserCommandExecutor

func (executor *BaseCommandExecutor) SetUserCommandExecutor(fn UserCommandExecutor)

SetUserCommandExecutor sets a command exector for database operation commands.

func (*BaseCommandExecutor) Update

func (executor *BaseCommandExecutor) Update(conn *Conn, q *Query) (int32, error)

Update hadles OP_UPDATE and 'update' query of OP_MSG.

type BaseMessageHandler

type BaseMessageHandler struct {
	CommandExecutor
	MessageExecutor
}

BaseMessageHandler is a complete hander for MessageHandler.

func NewBaseMessageHandler

func NewBaseMessageHandler() *BaseMessageHandler

NewBaseMessageHandler returns a complete null handler for MessageHandler.

func (*BaseMessageHandler) OpDelete

func (handler *BaseMessageHandler) OpDelete(conn *Conn, msg *OpDelete) (bson.Document, error)

OpDelete handles OP_DELETE of MongoDB wire protocol.

func (*BaseMessageHandler) OpGetMore

func (handler *BaseMessageHandler) OpGetMore(conn *Conn, msg *OpGetMore) (bson.Document, error)

OpGetMore handles GET_MORE of MongoDB wire protocol.

func (*BaseMessageHandler) OpInsert

func (handler *BaseMessageHandler) OpInsert(conn *Conn, msg *OpInsert) (bson.Document, error)

OpInsert handles OP_INSERT of MongoDB wire protocol.

func (*BaseMessageHandler) OpKillCursors

func (handler *BaseMessageHandler) OpKillCursors(conn *Conn, msg *OpKillCursors) (bson.Document, error)

OpKillCursors handles OP_KILL_CURSORS of MongoDB wire protocol.

func (*BaseMessageHandler) OpMsg

func (handler *BaseMessageHandler) OpMsg(conn *Conn, msg *OpMsg) (bson.Document, error)

OpMsg handles OP_MSG of MongoDB wire protocol.

func (*BaseMessageHandler) OpQuery

func (handler *BaseMessageHandler) OpQuery(conn *Conn, msg *OpQuery) (bson.Document, error)

OpQuery handles OP_QUERY of MongoDB wire protocol.

func (*BaseMessageHandler) OpUpdate

func (handler *BaseMessageHandler) OpUpdate(conn *Conn, msg *OpUpdate) (bson.Document, error)

OpUpdate handles OP_UPDATE of MongoDB wire protocol.

func (*BaseMessageHandler) SetCommandExecutor

func (handler *BaseMessageHandler) SetCommandExecutor(fn CommandExecutor)

SetCommandExecutor sets a exector for OP_QUERY of MongoDB wire protocol.

func (*BaseMessageHandler) SetMessageExecutor

func (handler *BaseMessageHandler) SetMessageExecutor(fn MessageExecutor)

SetMessageExecutor sets a exector for OP_MSG of MongoDB wire protocol.

type Client

type Client struct {
	Host       string
	Port       int
	Database   string
	Collection string
	Timeout    time.Duration
	// contains filtered or unexported fields
}

Client is an instance for Graphite protocols.

func NewClient

func NewClient() *Client

NewClient returns a client instance.

func (*Client) Close

func (client *Client) Close() error

Close closes the current connection.

func (*Client) Connect

func (client *Client) Connect() error

Connect connects the specified destination MongoDB server.

func (*Client) GetCollection

func (client *Client) GetCollection() string

GetCollection returns a destination collection.

func (*Client) GetDatabase

func (client *Client) GetDatabase() string

GetDatabase returns a destination database.

func (*Client) GetHost

func (client *Client) GetHost() string

GetHost returns a destination host.

func (*Client) GetPort

func (client *Client) GetPort() int

GetPort returns a destination port.

func (*Client) GetTimeout

func (client *Client) GetTimeout() time.Duration

GetTimeout return the timeout for the request.

func (*Client) InsertOne

func (client *Client) InsertOne(doc interface{}) error

InsertOne posts the specified document to the destination collection.

func (*Client) SetCollection

func (client *Client) SetCollection(col string)

SetCollection sets a destination collection.

func (*Client) SetDatabase

func (client *Client) SetDatabase(db string)

SetDatabase sets a destination database.

func (*Client) SetHost

func (client *Client) SetHost(host string)

SetHost sets a destination host.

func (*Client) SetPort

func (client *Client) SetPort(port int)

SetPort sets a destination port.

func (*Client) SetTimeout

func (client *Client) SetTimeout(d time.Duration)

SetTimeout sets a timeout for the request.

type Command

type Command = message.Command

Command represents a query command of MongoDB database command.

type CommandExecutor

type CommandExecutor interface {
	// ExecuteCommand handles query commands other than those explicitly specified above.
	ExecuteCommand(cmd *Command) (bson.Document, error)
}

CommandExecutor represents an interface for MongoDB database commands.

type Config

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

Config stores server configuration parammeters.

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns a default configuration instance.

func (*Config) GetCompressions

func (config *Config) GetCompressions() []string

GetCompressions should return supported compress strings.

func (*Config) GetLogicalSessionTimeoutMinutes

func (config *Config) GetLogicalSessionTimeoutMinutes() int32

GetLogicalSessionTimeoutMinutes should return a settion timeout value.

func (*Config) GetMaxBsonObjectSize

func (config *Config) GetMaxBsonObjectSize() int32

GetMaxBsonObjectSize should return a max limitation value of BSON object size.

func (*Config) GetMaxMessageSizeBytes

func (config *Config) GetMaxMessageSizeBytes() int32

GetMaxMessageSizeBytes should return a max limitation value of message size.

func (*Config) GetMaxWireVersion

func (config *Config) GetMaxWireVersion() int32

GetMaxWireVersion should return a max supported version.

func (*Config) GetMaxWriteBatchSize

func (config *Config) GetMaxWriteBatchSize() int32

GetMaxWriteBatchSize should return a max limitation value of write batch size.

func (*Config) GetMinWireVersion

func (config *Config) GetMinWireVersion() int32

GetMinWireVersion should return a min supported version.

func (*Config) GetReadOnly

func (config *Config) GetReadOnly() bool

GetReadOnly should return true when the instance does not support write operations.

func (*Config) GetVersion

func (config *Config) GetVersion() string

GetVersion should return supported MongoDB version string.

func (*Config) IsMaster

func (config *Config) IsMaster() bool

IsMaster should return true when the instance is running as master, otherwise false.

type Conn added in v0.9.2

type Conn struct {
	sync.Map

	tracer.Context
	// contains filtered or unexported fields
}

Conn represents a connection of Wire protocol.

func (*Conn) SpanContext added in v1.0.1

func (conn *Conn) SpanContext() tracer.Context

SpanContext returns the tracer span context of the connection.

func (*Conn) Timestamp added in v0.9.2

func (conn *Conn) Timestamp() time.Time

Timestamp returns the creation time of the connection.

type DatabaseCommandExecutor

DatabaseCommandExecutor represents an executor interface for MongoDB operation commands.

type DiagnosticCommandExecutor

type DiagnosticCommandExecutor interface {
	ExecuteBuildInfo(cmd *Command) (bson.Document, error)
}

DiagnosticCommandExecutor represents an executor interface for MongoDB diagnostic commands.

type Document

type Document = bsoncore.Document

Document represents a document of MongoDB wire protocol.

type MessageExecutor

type MessageExecutor interface {
	QueryCommandExecutor
}

MessageExecutor represents an executor interface for MongoDB message.

type MessageListener

type MessageListener interface {
	protocol.MessageListener
}

MessageListener represents a listener for MongoDB messages.

type OpDelete

type OpDelete = protocol.Delete

OpDelete (OP_DELETE:2006) deletes documents.

type OpFlag

type OpFlag = protocol.Flag

OpFlag represents a flag of MongoDB wire protocol.

type OpGetMore

type OpGetMore = protocol.GetMore

OpGetMore (GET_MORE:2005) gets more data from a query. See Cursors.

type OpInsert

type OpInsert = protocol.Insert

OpInsert (OP_INSERT:2002) inserts new document.

type OpKillCursors

type OpKillCursors = protocol.KillCursors

OpKillCursors (OP_KILL_CURSORS:2007) notifies database that the client has finished with the cursor.

type OpMessage

type OpMessage = protocol.Message

OpMessage represents a message of MongoDB wire protocol.

type OpMessageHandler

type OpMessageHandler interface {
	// Update handles OP_UPDATE of MongoDB wire protocol.
	OpUpdate(conn *Conn, q *OpUpdate) (bson.Document, error)
	// Insert handles OP_INSERT of MongoDB wire protocol.
	OpInsert(conn *Conn, q *OpInsert) (bson.Document, error)
	// Query handles OP_QUERY of MongoDB wire protocol.
	OpQuery(conn *Conn, q *OpQuery) (bson.Document, error)
	// GetMore handles GET_MORE of MongoDB wire protocol.
	OpGetMore(conn *Conn, q *OpGetMore) (bson.Document, error)
	// Delete handles OP_DELETE of MongoDB wire protocol.
	OpDelete(conn *Conn, q *OpDelete) (bson.Document, error)
	// KillCursors handles OP_KILL_CURSORS of MongoDB wire protocol.
	OpKillCursors(conn *Conn, q *OpKillCursors) (bson.Document, error)
	// Msg handles OP_MSG of MongoDB wire protocol.
	OpMsg(conn *Conn, q *OpMsg) (bson.Document, error)
}

OpMessageHandler represents an interface for MongoDB query request.

type OpMsg

type OpMsg = protocol.Msg

OpMsg (OP_MSG:2013) sends a message using the format introduced in MongoDB 3.6.

type OpQuery

type OpQuery = protocol.Query

OpQuery (OP_QUERY:2004) queries a collection.

type OpReply

type OpReply = protocol.Reply

OpReply (OP_REPLY) replies to a client request. responseTo is set.

type OpUpdate

type OpUpdate = protocol.Update

OpUpdate (OP_UPDATE:2001) updates document.

type Query

type Query = message.Query

Query represents a query of MongoDB database command.

type QueryCommandExecutor added in v0.9.2

type QueryCommandExecutor interface {
	// Insert hadles OP_INSERT and 'insert' query of OP_MSG.
	Insert(*Conn, *Query) (int32, error)
	// Update hadles OP_UPDATE and 'update' query of OP_MSG.
	Update(*Conn, *Query) (int32, error)
	// Find hadles 'find' query of OP_MSG.
	Find(*Conn, *Query) ([]bson.Document, error)
	// Delete hadles OP_DELETE and 'delete' query of OP_MSG.
	Delete(*Conn, *Query) (int32, error)
}

QueryCommandExecutor represents an executor interface for MongoDB queries.

type ReplicationCommandExecutor

type ReplicationCommandExecutor interface {
	ExecuteIsMaster(cmd *Command) (bson.Document, error)
}

ReplicationCommandExecutor represents an executor interface for MongoDB replication commands.

type Server

type Server struct {
	*Config
	tracer.Tracer
	Addr string
	Port int

	MessageHandler OpMessageHandler

	*BaseMessageHandler
	*BaseCommandExecutor
	// contains filtered or unexported fields
}

Server is an instance for MongoDB protocols.

func NewServer

func NewServer() *Server

NewServer returns a new server instance.

func (*Server) ExecuteBuildInfo

func (server *Server) ExecuteBuildInfo(cmd *Command) (bson.Document, error)

ExecuteBuildInfo returns statistics about the MongoDB build.

func (*Server) ExecuteIsMaster

func (server *Server) ExecuteIsMaster(cmd *Command) (bson.Document, error)

ExecuteIsMaster displays information about this member’s role in the replica set, including whether it is the master.

func (*Server) GetAddress added in v1.0.0

func (server *Server) GetAddress() string

GetAddress returns a listen address.

func (*Server) GetPort

func (server *Server) GetPort() int

GetPort returns a listent port.

func (*Server) Restart

func (server *Server) Restart() error

Restart restarts the server.

func (*Server) SetAddress added in v1.0.0

func (server *Server) SetAddress(addr string)

SetAddress sets a listen address.

func (*Server) SetMessageHandler

func (server *Server) SetMessageHandler(h OpMessageHandler)

SetMessageHandler sets a message handler.

func (*Server) SetMessageListener

func (server *Server) SetMessageListener(l MessageListener)

SetMessageListener sets a message listener.

func (*Server) SetPort

func (server *Server) SetPort(port int)

SetPort sets a listen port.

func (*Server) SetTracer added in v0.9.5

func (server *Server) SetTracer(t tracer.Tracer)

SetTracer sets a tracing tracer.

func (*Server) Start

func (server *Server) Start() error

Start starts the server.

func (*Server) Stop

func (server *Server) Stop() error

Stop stops the server.

type UserCommandExecutor

type UserCommandExecutor interface {
	QueryCommandExecutor
}

UserCommandExecutor represents an executor interface for MongoDB query commands.

type WriteOperationExecutor

type WriteOperationExecutor interface {
	ExecuteGetLastError(cmd *Command) (bson.Document, error)
}

WriteOperationExecutor represents an executor interface for MongoDB write operation commands.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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