command

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package command contains abstractions for operations that can be performed against a MongoDB deployment. The types in this package are meant to provide a general set of commands that a user can run against a MongoDB database without knowing the version of the database.

Each type consists of two levels of interaction. The lowest level are the Encode and Decode methods. These are meant to be symmetric eventually, but currently only support the driver side of commands. The higher level is the RoundTrip method. This only makes sense from the driver side of commands and this method handles the encoding of the request and decoding of the response using the given wiremessage.ReadWriter.

Index

Constants

View Source
const BatchSize = 10000

BatchSize is the max number of sessions to be included in 1 endSessions command.

Variables

View Source
var (
	// ErrUnknownCommandFailure occurs when a command fails for an unknown reason.
	ErrUnknownCommandFailure = errors.New("unknown command failure")
	// ErrNoCommandResponse occurs when the server sent no response document to a command.
	ErrNoCommandResponse = errors.New("no command response document")
	// ErrMultiDocCommandResponse occurs when the server sent multiple documents in response to a command.
	ErrMultiDocCommandResponse = errors.New("command returned multiple documents")
	// ErrNoDocCommandResponse occurs when the server indicated a response existed, but none was found.
	ErrNoDocCommandResponse = errors.New("command returned no documents")
	// ErrDocumentTooLarge occurs when a document that is larger than the maximum size accepted by a
	// server is passed to an insert command.
	ErrDocumentTooLarge = errors.New("an inserted document is too large")
	// ErrNonPrimaryRP occurs when a nonprimary read preference is used with a transaction.
	ErrNonPrimaryRP = errors.New("read preference in a transaction must be primary")
	// UnknownTransactionCommitResult is an error label for unknown transaction commit results.
	UnknownTransactionCommitResult = "UnknownTransactionCommitResult"
	// TransientTransactionError is an error label for transient errors with transactions.
	TransientTransactionError = "TransientTransactionError"
	// NetworkError is an error label for network errors.
	NetworkError = "NetworkError"
)
View Source
var ErrUnacknowledgedWrite = errors.New("unacknowledged write")

ErrUnacknowledgedWrite is returned from functions that have an unacknowledged write concern.

Functions

func ClientDoc

func ClientDoc(app string) bsonx.Doc

ClientDoc creates a client information document for use in an isMaster command.

func DecodeError

func DecodeError(wm wiremessage.WireMessage) error

DecodeError attempts to decode the wiremessage as an error

func IsNotFound

func IsNotFound(err error) bool

IsNotFound indicates if the error is from a namespace not being found.

func IsWriteConcernErrorRetryable

func IsWriteConcernErrorRetryable(wce *result.WriteConcernError) bool

IsWriteConcernErrorRetryable returns true if the write concern error is retryable.

Types

type AbortTransaction

type AbortTransaction struct {
	Session *session.Client
	// contains filtered or unexported fields
}

AbortTransaction represents the abortTransaction() command

func (*AbortTransaction) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*AbortTransaction) Encode

Encode will encode this command into a wiremessage for the given server description.

func (*AbortTransaction) Err

func (at *AbortTransaction) Err() error

Err returns the error set on this command

func (*AbortTransaction) Result

Result returns the result of a decoded wire message and server description.

func (*AbortTransaction) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter

type Aggregate

type Aggregate struct {
	NS           Namespace
	Pipeline     bsonx.Arr
	CursorOpts   []bsonx.Elem
	Opts         []bsonx.Elem
	ReadPref     *readpref.ReadPref
	WriteConcern *writeconcern.WriteConcern
	ReadConcern  *readconcern.ReadConcern
	Clock        *session.ClusterClock
	Session      *session.Client
	// contains filtered or unexported fields
}

Aggregate represents the aggregate command.

The aggregate command performs an aggregation.

func (*Aggregate) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Aggregate) Encode

Encode will encode this command into a wire message for the given server description.

func (*Aggregate) Err

func (a *Aggregate) Err() error

Err returns the error set on this command.

func (*Aggregate) HasDollarOut

func (a *Aggregate) HasDollarOut() bool

HasDollarOut returns true if the Pipeline field contains a $out stage.

func (*Aggregate) Result

func (a *Aggregate) Result() (Cursor, error)

Result returns the result of a decoded wire message and server description.

func (*Aggregate) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type BuildInfo

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

BuildInfo represents the buildInfo command.

The buildInfo command is used for getting the build information for a MongoDB server.

func (*BuildInfo) Decode

func (bi *BuildInfo) Decode(wm wiremessage.WireMessage) *BuildInfo

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*BuildInfo) Encode

func (bi *BuildInfo) Encode() (wiremessage.WireMessage, error)

Encode will encode this command into a wire message for the given server description.

func (*BuildInfo) Err

func (bi *BuildInfo) Err() error

Err returns the error set on this command.

func (*BuildInfo) Result

func (bi *BuildInfo) Result() (result.BuildInfo, error)

Result returns the result of a decoded wire message and server description.

func (*BuildInfo) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type CommitTransaction

type CommitTransaction struct {
	Session *session.Client
	// contains filtered or unexported fields
}

CommitTransaction represents the commitTransaction() command

func (*CommitTransaction) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*CommitTransaction) Encode

Encode will encode this command into a wiremessage for the given server description.

func (*CommitTransaction) Err

func (ct *CommitTransaction) Err() error

Err returns the error set on this command

func (*CommitTransaction) Result

Result returns the result of a decoded wire message and server description.

func (*CommitTransaction) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter

type Count

type Count struct {
	NS          Namespace
	Query       bsonx.Doc
	Opts        []bsonx.Elem
	ReadPref    *readpref.ReadPref
	ReadConcern *readconcern.ReadConcern
	Clock       *session.ClusterClock
	Session     *session.Client
	// contains filtered or unexported fields
}

Count represents the count command.

The count command counts how many documents in a collection match the given query.

func (*Count) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Count) Encode

Encode will encode this command into a wire message for the given server description.

func (*Count) Err

func (c *Count) Err() error

Err returns the error set on this command.

func (*Count) Result

func (c *Count) Result() (int64, error)

Result returns the result of a decoded wire message and server description.

func (*Count) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type CountDocuments

type CountDocuments struct {
	NS          Namespace
	Pipeline    bsonx.Arr
	Opts        []bsonx.Elem
	ReadPref    *readpref.ReadPref
	ReadConcern *readconcern.ReadConcern
	Clock       *session.ClusterClock
	Session     *session.Client
	// contains filtered or unexported fields
}

CountDocuments represents the CountDocuments command.

The countDocuments command counts how many documents in a collection match the given query.

func (*CountDocuments) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*CountDocuments) Encode

Encode will encode this command into a wire message for the given server description.

func (*CountDocuments) Err

func (c *CountDocuments) Err() error

Err returns the error set on this command.

func (*CountDocuments) Result

func (c *CountDocuments) Result() (int64, error)

Result returns the result of a decoded wire message and server description.

func (*CountDocuments) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type CreateIndexes

type CreateIndexes struct {
	NS           Namespace
	Indexes      bsonx.Arr
	Opts         []bsonx.Elem
	WriteConcern *writeconcern.WriteConcern
	Clock        *session.ClusterClock
	Session      *session.Client
	// contains filtered or unexported fields
}

CreateIndexes represents the createIndexes command.

The createIndexes command creates indexes for a namespace.

func (*CreateIndexes) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*CreateIndexes) Encode

Encode will encode this command into a wire message for the given server description.

func (*CreateIndexes) Err

func (ci *CreateIndexes) Err() error

Err returns the error set on this command.

func (*CreateIndexes) Result

func (ci *CreateIndexes) Result() (result.CreateIndexes, error)

Result returns the result of a decoded wire message and server description.

func (*CreateIndexes) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type Cursor

type Cursor interface {
	// Get the ID of the cursor.
	ID() int64

	// Get the next result from the cursor.
	// Returns true if there were no errors and there is a next result.
	Next(context.Context) bool

	// Decode the next document into the provided object according to the
	// rules of the bson package.
	Decode(interface{}) error

	// Returns the next document as a bson.Reader. The user must copy the
	// bytes to retain them.
	DecodeBytes() (bson.Raw, error)

	// Returns the error status of the cursor
	Err() error

	// Close the cursor.
	Close(context.Context) error
}

Cursor instances iterate a stream of documents. Each document is decoded into the result according to the rules of the bson package.

A typical usage of the Cursor interface would be:

var cur Cursor
ctx := context.Background()
defer cur.Close(ctx)

for cur.Next(ctx) {
	elem := bson.NewDocument()
	if err := cur.Decode(elem); err != nil {
		log.Fatal(err)
	}

	// do something with elem....
}

if err := cur.Err(); err != nil {
	log.Fatal(err)
}

type CursorBuilder

type CursorBuilder interface {
	BuildCursor(bson.Raw, *session.Client, *session.ClusterClock, ...bsonx.Elem) (Cursor, error)
}

CursorBuilder is a type that can build a Cursor.

type Delete

type Delete struct {
	ContinueOnError bool
	NS              Namespace
	Deletes         []bsonx.Doc
	Opts            []bsonx.Elem
	WriteConcern    *writeconcern.WriteConcern
	Clock           *session.ClusterClock
	Session         *session.Client
	// contains filtered or unexported fields
}

Delete represents the delete command.

The delete command executes a delete with a given set of delete documents and options.

func (*Delete) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Delete) Encode

Encode will encode this command into a wire message for the given server description.

func (*Delete) Err

func (d *Delete) Err() error

Err returns the error set on this command.

func (*Delete) Result

func (d *Delete) Result() (result.Delete, error)

Result returns the result of a decoded wire message and server description.

func (*Delete) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type Distinct

type Distinct struct {
	NS          Namespace
	Field       string
	Query       bsonx.Doc
	Opts        []bsonx.Elem
	ReadPref    *readpref.ReadPref
	ReadConcern *readconcern.ReadConcern
	Clock       *session.ClusterClock
	Session     *session.Client
	// contains filtered or unexported fields
}

Distinct represents the disctinct command.

The distinct command returns the distinct values for a specified field across a single collection.

func (*Distinct) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Distinct) Encode

Encode will encode this command into a wire message for the given server description.

func (*Distinct) Err

func (d *Distinct) Err() error

Err returns the error set on this command.

func (*Distinct) Result

func (d *Distinct) Result() (result.Distinct, error)

Result returns the result of a decoded wire message and server description.

func (*Distinct) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type DropCollection

type DropCollection struct {
	DB           string
	Collection   string
	WriteConcern *writeconcern.WriteConcern
	Clock        *session.ClusterClock
	Session      *session.Client
	// contains filtered or unexported fields
}

DropCollection represents the drop command.

The dropCollections command drops collection for a database.

func (*DropCollection) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*DropCollection) Encode

Encode will encode this command into a wire message for the given server description.

func (*DropCollection) Err

func (dc *DropCollection) Err() error

Err returns the error set on this command.

func (*DropCollection) Result

func (dc *DropCollection) Result() (bson.Raw, error)

Result returns the result of a decoded wire message and server description.

func (*DropCollection) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type DropDatabase

type DropDatabase struct {
	DB           string
	WriteConcern *writeconcern.WriteConcern
	Clock        *session.ClusterClock
	Session      *session.Client
	// contains filtered or unexported fields
}

DropDatabase represents the DropDatabase command.

The DropDatabases command drops database.

func (*DropDatabase) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*DropDatabase) Encode

Encode will encode this command into a wire message for the given server description.

func (*DropDatabase) Err

func (dd *DropDatabase) Err() error

Err returns the error set on this command.

func (*DropDatabase) Result

func (dd *DropDatabase) Result() (bson.Raw, error)

Result returns the result of a decoded wire message and server description.

func (*DropDatabase) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type DropIndexes

type DropIndexes struct {
	NS           Namespace
	Index        string
	Opts         []bsonx.Elem
	WriteConcern *writeconcern.WriteConcern
	Clock        *session.ClusterClock
	Session      *session.Client
	// contains filtered or unexported fields
}

DropIndexes represents the dropIndexes command.

The dropIndexes command drops indexes for a namespace.

func (*DropIndexes) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*DropIndexes) Encode

Encode will encode this command into a wire message for the given server description.

func (*DropIndexes) Err

func (di *DropIndexes) Err() error

Err returns the error set on this command.

func (*DropIndexes) Result

func (di *DropIndexes) Result() (bson.Raw, error)

Result returns the result of a decoded wire message and server description.

func (*DropIndexes) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type EndSessions

type EndSessions struct {
	Clock      *session.ClusterClock
	SessionIDs []bsonx.Doc
	// contains filtered or unexported fields
}

EndSessions represents an endSessions command.

func (*EndSessions) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*EndSessions) Encode

Encode will encode this command into a series of wire messages for the given server description.

func (*EndSessions) Result

func (es *EndSessions) Result() ([]result.EndSessions, []error)

Result returns the results of the decoded wire messages.

func (*EndSessions) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter

type Error

type Error struct {
	Code    int32
	Message string
	Labels  []string
	Name    string
}

Error is a command execution error from the database.

func (Error) Error

func (e Error) Error() string

Error implements the error interface.

func (Error) HasErrorLabel

func (e Error) HasErrorLabel(label string) bool

HasErrorLabel returns true if the error contains the specified label.

func (Error) Retryable

func (e Error) Retryable() bool

Retryable returns true if the error is retryable

type Find

type Find struct {
	NS          Namespace
	Filter      bsonx.Doc
	CursorOpts  []bsonx.Elem
	Opts        []bsonx.Elem
	ReadPref    *readpref.ReadPref
	ReadConcern *readconcern.ReadConcern
	Clock       *session.ClusterClock
	Session     *session.Client
	// contains filtered or unexported fields
}

Find represents the find command.

The find command finds documents within a collection that match a filter.

func (*Find) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Find) Encode

Encode will encode this command into a wire message for the given server description.

func (*Find) Err

func (f *Find) Err() error

Err returns the error set on this command.

func (*Find) Result

func (f *Find) Result() (Cursor, error)

Result returns the result of a decoded wire message and server description.

func (*Find) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type FindOneAndDelete

type FindOneAndDelete struct {
	NS           Namespace
	Query        bsonx.Doc
	Opts         []bsonx.Elem
	WriteConcern *writeconcern.WriteConcern
	Clock        *session.ClusterClock
	Session      *session.Client
	// contains filtered or unexported fields
}

FindOneAndDelete represents the findOneAndDelete operation.

The findOneAndDelete command deletes a single document that matches a query and returns it.

func (*FindOneAndDelete) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*FindOneAndDelete) Encode

Encode will encode this command into a wire message for the given server description.

func (*FindOneAndDelete) Err

func (f *FindOneAndDelete) Err() error

Err returns the error set on this command.

func (*FindOneAndDelete) Result

func (f *FindOneAndDelete) Result() (result.FindAndModify, error)

Result returns the result of a decoded wire message and server description.

func (*FindOneAndDelete) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type FindOneAndReplace

type FindOneAndReplace struct {
	NS           Namespace
	Query        bsonx.Doc
	Replacement  bsonx.Doc
	Opts         []bsonx.Elem
	WriteConcern *writeconcern.WriteConcern
	Clock        *session.ClusterClock
	Session      *session.Client
	// contains filtered or unexported fields
}

FindOneAndReplace represents the findOneAndReplace operation.

The findOneAndReplace command modifies and returns a single document.

func (*FindOneAndReplace) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*FindOneAndReplace) Encode

Encode will encode this command into a wire message for the given server description.

func (*FindOneAndReplace) Err

func (f *FindOneAndReplace) Err() error

Err returns the error set on this command.

func (*FindOneAndReplace) Result

Result returns the result of a decoded wire message and server description.

func (*FindOneAndReplace) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type FindOneAndUpdate

type FindOneAndUpdate struct {
	NS           Namespace
	Query        bsonx.Doc
	Update       bsonx.Doc
	Opts         []bsonx.Elem
	WriteConcern *writeconcern.WriteConcern
	Clock        *session.ClusterClock
	Session      *session.Client
	// contains filtered or unexported fields
}

FindOneAndUpdate represents the findOneAndUpdate operation.

The findOneAndUpdate command modifies and returns a single document.

func (*FindOneAndUpdate) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*FindOneAndUpdate) Encode

Encode will encode this command into a wire message for the given server description.

func (*FindOneAndUpdate) Err

func (f *FindOneAndUpdate) Err() error

Err returns the error set on this command.

func (*FindOneAndUpdate) Result

func (f *FindOneAndUpdate) Result() (result.FindAndModify, error)

Result returns the result of a decoded wire message and server description.

func (*FindOneAndUpdate) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type GetLastError

type GetLastError struct {
	Clock   *session.ClusterClock
	Session *session.Client
	// contains filtered or unexported fields
}

GetLastError represents the getLastError command.

The getLastError command is used for getting the last error from the last command on a connection.

Since GetLastError only makes sense in the context of a single connection, there is no Dispatch method.

func (*GetLastError) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*GetLastError) Encode

func (gle *GetLastError) Encode() (wiremessage.WireMessage, error)

Encode will encode this command into a wire message for the given server description.

func (*GetLastError) Err

func (gle *GetLastError) Err() error

Err returns the error set on this command.

func (*GetLastError) Result

func (gle *GetLastError) Result() (result.GetLastError, error)

Result returns the result of a decoded wire message and server description.

func (*GetLastError) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type GetMore

type GetMore struct {
	ID      int64
	NS      Namespace
	Opts    []bsonx.Elem
	Clock   *session.ClusterClock
	Session *session.Client
	// contains filtered or unexported fields
}

GetMore represents the getMore command.

The getMore command retrieves additional documents from a cursor.

func (*GetMore) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*GetMore) Encode

Encode will encode this command into a wire message for the given server description.

func (*GetMore) Err

func (gm *GetMore) Err() error

Err returns the error set on this command.

func (*GetMore) Result

func (gm *GetMore) Result() (bson.Raw, error)

Result returns the result of a decoded wire message and server description.

func (*GetMore) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type Handshake

type Handshake struct {
	Client             bsonx.Doc
	Compressors        []string
	SaslSupportedMechs string
	// contains filtered or unexported fields
}

Handshake represents a generic MongoDB Handshake. It calls isMaster and buildInfo.

The isMaster and buildInfo commands are used to build a server description.

func (*Handshake) Decode

func (h *Handshake) Decode(wm wiremessage.WireMessage) *Handshake

Decode will decode the wire messages. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Handshake) Encode

func (h *Handshake) Encode() (wiremessage.WireMessage, error)

Encode will encode the handshake commands into a wire message containing isMaster

func (*Handshake) Err

func (h *Handshake) Err() error

Err returns the error set on this Handshake.

func (*Handshake) Handshake

Handshake implements the connection.Handshaker interface. It is identical to the RoundTrip methods on other types in this package. It will execute the isMaster command.

func (*Handshake) Result

func (h *Handshake) Result(addr address.Address) (description.Server, error)

Result returns the result of decoded wire messages.

type Insert

type Insert struct {
	ContinueOnError bool
	Clock           *session.ClusterClock
	NS              Namespace
	Docs            []bsonx.Doc
	Opts            []bsonx.Elem
	WriteConcern    *writeconcern.WriteConcern
	Session         *session.Client
	// contains filtered or unexported fields
}

Insert represents the insert command.

The insert command inserts a set of documents into the database.

Since the Insert command does not return any value other than ok or an error, this type has no Err method.

func (*Insert) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Insert) Encode

Encode will encode this command into a wire message for the given server description.

func (*Insert) Err

func (i *Insert) Err() error

Err returns the error set on this command.

func (*Insert) Result

func (i *Insert) Result() (result.Insert, error)

Result returns the result of a decoded wire message and server description.

func (*Insert) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter. func (i *Insert) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.Insert, error) {

type IsMaster

type IsMaster struct {
	Client             bsonx.Doc
	Compressors        []string
	SaslSupportedMechs string
	// contains filtered or unexported fields
}

IsMaster represents the isMaster command.

The isMaster command is used for setting up a connection to MongoDB and for monitoring a MongoDB server.

Since IsMaster can only be run on a connection, there is no Dispatch method.

func (*IsMaster) Decode

func (im *IsMaster) Decode(wm wiremessage.WireMessage) *IsMaster

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*IsMaster) Encode

func (im *IsMaster) Encode() (wiremessage.WireMessage, error)

Encode will encode this command into a wire message for the given server description.

func (*IsMaster) Err

func (im *IsMaster) Err() error

Err returns the error set on this command.

func (*IsMaster) Result

func (im *IsMaster) Result() (result.IsMaster, error)

Result returns the result of a decoded wire message and server description.

func (*IsMaster) RoundTrip

func (im *IsMaster) RoundTrip(ctx context.Context, rw wiremessage.ReadWriter) (result.IsMaster, error)

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type KillCursors

type KillCursors struct {
	Clock *session.ClusterClock
	NS    Namespace
	IDs   []int64
	// contains filtered or unexported fields
}

KillCursors represents the killCursors command.

The killCursors command kills a set of cursors.

func (*KillCursors) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*KillCursors) Encode

Encode will encode this command into a wire message for the given server description.

func (*KillCursors) Err

func (kc *KillCursors) Err() error

Err returns the error set on this command.

func (*KillCursors) Result

func (kc *KillCursors) Result() (result.KillCursors, error)

Result returns the result of a decoded wire message and server description.

func (*KillCursors) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type ListCollections

type ListCollections struct {
	Clock      *session.ClusterClock
	DB         string
	Filter     bsonx.Doc
	CursorOpts []bsonx.Elem
	Opts       []bsonx.Elem
	ReadPref   *readpref.ReadPref
	Session    *session.Client
	// contains filtered or unexported fields
}

ListCollections represents the listCollections command.

The listCollections command lists the collections in a database.

func (*ListCollections) Decode

Decode will decode the wire message using the provided server description. Errors during decolcng are deferred until either the Result or Err methods are called.

func (*ListCollections) Encode

Encode will encode this command into a wire message for the given server description.

func (*ListCollections) Err

func (lc *ListCollections) Err() error

Err returns the error set on this command.

func (*ListCollections) Result

func (lc *ListCollections) Result() (Cursor, error)

Result returns the result of a decoded wire message and server description.

func (*ListCollections) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type ListDatabases

type ListDatabases struct {
	Clock   *session.ClusterClock
	Filter  bsonx.Doc
	Opts    []bsonx.Elem
	Session *session.Client
	// contains filtered or unexported fields
}

ListDatabases represents the listDatabases command.

The listDatabases command lists the databases in a MongoDB deployment.

func (*ListDatabases) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*ListDatabases) Encode

Encode will encode this command into a wire message for the given server description.

func (*ListDatabases) Err

func (ld *ListDatabases) Err() error

Err returns the error set on this command.

func (*ListDatabases) Result

func (ld *ListDatabases) Result() (result.ListDatabases, error)

Result returns the result of a decoded wire message and server description.

func (*ListDatabases) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type ListIndexes

type ListIndexes struct {
	Clock      *session.ClusterClock
	NS         Namespace
	CursorOpts []bsonx.Elem
	Opts       []bsonx.Elem
	Session    *session.Client
	// contains filtered or unexported fields
}

ListIndexes represents the listIndexes command.

The listIndexes command lists the indexes for a namespace.

func (*ListIndexes) Decode

Decode will decode the wire message using the provided server description. Errors during decoling are deferred until either the Result or Err methods are called.

func (*ListIndexes) Encode

Encode will encode this command into a wire message for the given server description.

func (*ListIndexes) Err

func (li *ListIndexes) Err() error

Err returns the error set on this command.

func (*ListIndexes) Result

func (li *ListIndexes) Result() (Cursor, error)

Result returns the result of a decoded wire message and server description.

func (*ListIndexes) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type Namespace

type Namespace struct {
	DB         string
	Collection string
}

Namespace encapsulates a database and collection name, which together uniquely identifies a collection within a MongoDB cluster.

func NewNamespace

func NewNamespace(db, collection string) Namespace

NewNamespace returns a new Namespace for the given database and collection.

func ParseNamespace

func ParseNamespace(name string) Namespace

ParseNamespace parses a namespace string into a Namespace.

The namespace string must contain at least one ".", the first of which is the separator between the database and collection names. If not, the default (invalid) Namespace is returned.

func (*Namespace) FullName

func (ns *Namespace) FullName() string

FullName returns the full namespace string, which is the result of joining the database name and the collection name with a "." character.

func (*Namespace) Validate

func (ns *Namespace) Validate() error

Validate validates the namespace.

type QueryFailureError

type QueryFailureError struct {
	Message  string
	Response bson.Raw
}

QueryFailureError is an error representing a command failure as a document.

func (QueryFailureError) Error

func (e QueryFailureError) Error() string

Error implements the error interface.

type Read

type Read struct {
	DB          string
	Command     bsonx.Doc
	ReadPref    *readpref.ReadPref
	ReadConcern *readconcern.ReadConcern
	Clock       *session.ClusterClock
	Session     *session.Client
	// contains filtered or unexported fields
}

Read represents a generic database read command.

func (*Read) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Read) Encode

Encode will encode this command into a wire message for the given server description.

func (*Read) Err

func (r *Read) Err() error

Err returns the error set on this command.

func (*Read) Result

func (r *Read) Result() (bson.Raw, error)

Result returns the result of a decoded wire message and server description.

func (*Read) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type ResponseError

type ResponseError struct {
	Message string
	Wrapped error
}

ResponseError is an error parsing the response to a command.

func NewCommandResponseError

func NewCommandResponseError(msg string, err error) ResponseError

NewCommandResponseError creates a CommandResponseError.

func (ResponseError) Error

func (e ResponseError) Error() string

Error implements the error interface.

type StartSession

type StartSession struct {
	Clock *session.ClusterClock
	// contains filtered or unexported fields
}

StartSession represents a startSession command

func (*StartSession) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*StartSession) Encode

Encode will encode this command into a wiremessage for the given server description.

func (*StartSession) Err

func (ss *StartSession) Err() error

Err returns the error set on this command

func (*StartSession) Result

func (ss *StartSession) Result() (result.StartSession, error)

Result returns the result of a decoded wire message and server description.

func (*StartSession) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter

type Update

type Update struct {
	ContinueOnError bool
	Clock           *session.ClusterClock
	NS              Namespace
	Docs            []bsonx.Doc
	Opts            []bsonx.Elem
	WriteConcern    *writeconcern.WriteConcern
	Session         *session.Client
	// contains filtered or unexported fields
}

Update represents the update command.

The update command updates a set of documents with the database.

func (*Update) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Update) Encode

Encode will encode this command into a wire message for the given server description.

func (*Update) Err

func (u *Update) Err() error

Err returns the error set on this command.

func (*Update) Result

func (u *Update) Result() (result.Update, error)

Result returns the result of a decoded wire message and server description.

func (*Update) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.

type Write

type Write struct {
	DB           string
	Command      bsonx.Doc
	WriteConcern *writeconcern.WriteConcern
	Clock        *session.ClusterClock
	Session      *session.Client
	// contains filtered or unexported fields
}

Write represents a generic write database command. This can be used to send arbitrary write commands to the database.

func (*Write) Decode

Decode will decode the wire message using the provided server description. Errors during decoding are deferred until either the Result or Err methods are called.

func (*Write) Encode

Encode will encode this command into a wire message for the given server description.

func (*Write) Err

func (w *Write) Err() error

Err returns the error set on this command.

func (*Write) Result

func (w *Write) Result() (bson.Raw, error)

Result returns the result of a decoded wire message and server description.

func (*Write) RoundTrip

RoundTrip handles the execution of this command using the provided wiremessage.ReadWriteCloser.

type WriteBatch

type WriteBatch struct {
	*Write
	// contains filtered or unexported fields
}

WriteBatch represents a single batch for a write operation.

type WriteCommandKind

type WriteCommandKind int8

WriteCommandKind is the type of command represented by a Write

const (
	InsertCommand WriteCommandKind = iota
	UpdateCommand
	DeleteCommand
)

These constants represent the valid types of write commands.

Jump to

Keyboard shortcuts

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