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 ¶
- Variables
- func ClientDoc(app string) *bson.Document
- func IsNotFound(err error) bool
- type Aggregate
- func (a *Aggregate) Decode(desc description.SelectedServer, cb CursorBuilder, wm wiremessage.WireMessage) *Aggregate
- func (a *Aggregate) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (a *Aggregate) Err() error
- func (a *Aggregate) HasDollarOut() bool
- func (a *Aggregate) Result() (Cursor, error)
- func (a *Aggregate) RoundTrip(ctx context.Context, desc description.SelectedServer, cb CursorBuilder, ...) (Cursor, error)
- type BuildInfo
- func (bi *BuildInfo) Decode(wm wiremessage.WireMessage) *BuildInfo
- func (bi *BuildInfo) Encode() (wiremessage.WireMessage, error)
- func (bi *BuildInfo) Err() error
- func (bi *BuildInfo) Result() (result.BuildInfo, error)
- func (bi *BuildInfo) RoundTrip(ctx context.Context, rw wiremessage.ReadWriter) (result.BuildInfo, error)
- type Command
- func (c *Command) Decode(_ description.SelectedServer, wm wiremessage.WireMessage) *Command
- func (c *Command) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (c *Command) Err() error
- func (c *Command) Result() (bson.Reader, error)
- func (c *Command) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (bson.Reader, error)
- type Count
- func (c *Count) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Count
- func (c *Count) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (c *Count) Err() error
- func (c *Count) Result() (int64, error)
- func (c *Count) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (int64, error)
- type CreateIndexes
- func (ci *CreateIndexes) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *CreateIndexes
- func (ci *CreateIndexes) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (ci *CreateIndexes) Err() error
- func (ci *CreateIndexes) Result() (result.CreateIndexes, error)
- func (ci *CreateIndexes) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.CreateIndexes, error)
- type Cursor
- type CursorBuilder
- type Delete
- func (d *Delete) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Delete
- func (d *Delete) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (d *Delete) Err() error
- func (d *Delete) Result() (result.Delete, error)
- func (d *Delete) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.Delete, error)
- type Distinct
- func (d *Distinct) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Distinct
- func (d *Distinct) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (d *Distinct) Err() error
- func (d *Distinct) Result() (result.Distinct, error)
- func (d *Distinct) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.Distinct, error)
- type DropCollection
- func (di *DropCollection) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *DropCollection
- func (di *DropCollection) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (di *DropCollection) Err() error
- func (di *DropCollection) Result() (bson.Reader, error)
- func (di *DropCollection) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (bson.Reader, error)
- type DropDatabase
- func (dd *DropDatabase) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *DropDatabase
- func (dd *DropDatabase) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (dd *DropDatabase) Err() error
- func (dd *DropDatabase) Result() (bson.Reader, error)
- func (dd *DropDatabase) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (bson.Reader, error)
- type DropIndexes
- func (di *DropIndexes) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *DropIndexes
- func (di *DropIndexes) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (di *DropIndexes) Err() error
- func (di *DropIndexes) Result() (bson.Reader, error)
- func (di *DropIndexes) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (bson.Reader, error)
- type Error
- type Find
- func (f *Find) Decode(desc description.SelectedServer, cb CursorBuilder, wm wiremessage.WireMessage) *Find
- func (f *Find) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (f *Find) Err() error
- func (f *Find) Result() (Cursor, error)
- func (f *Find) RoundTrip(ctx context.Context, desc description.SelectedServer, cb CursorBuilder, ...) (Cursor, error)
- type FindOneAndDelete
- func (f *FindOneAndDelete) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *FindOneAndDelete
- func (f *FindOneAndDelete) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (f *FindOneAndDelete) Err() error
- func (f *FindOneAndDelete) Result() (result.FindAndModify, error)
- func (f *FindOneAndDelete) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.FindAndModify, error)
- type FindOneAndReplace
- func (f *FindOneAndReplace) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *FindOneAndReplace
- func (f *FindOneAndReplace) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (f *FindOneAndReplace) Err() error
- func (f *FindOneAndReplace) Result() (result.FindAndModify, error)
- func (f *FindOneAndReplace) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.FindAndModify, error)
- type FindOneAndUpdate
- func (f *FindOneAndUpdate) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *FindOneAndUpdate
- func (f *FindOneAndUpdate) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (f *FindOneAndUpdate) Err() error
- func (f *FindOneAndUpdate) Result() (result.FindAndModify, error)
- func (f *FindOneAndUpdate) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.FindAndModify, error)
- type GetLastError
- func (gle *GetLastError) Decode(wm wiremessage.WireMessage) *GetLastError
- func (gle *GetLastError) Encode() (wiremessage.WireMessage, error)
- func (gle *GetLastError) Err() error
- func (gle *GetLastError) Result() (result.GetLastError, error)
- func (gle *GetLastError) RoundTrip(ctx context.Context, rw wiremessage.ReadWriter) (result.GetLastError, error)
- type GetMore
- func (gm *GetMore) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *GetMore
- func (gm *GetMore) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (gm *GetMore) Err() error
- func (gm *GetMore) Result() (bson.Reader, error)
- func (gm *GetMore) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (bson.Reader, error)
- type Handshake
- func (h *Handshake) Decode(wms [2]wiremessage.WireMessage) *Handshake
- func (h *Handshake) Encode() ([2]wiremessage.WireMessage, error)
- func (h *Handshake) Err() error
- func (h *Handshake) Handshake(ctx context.Context, address addr.Addr, rw wiremessage.ReadWriter) (description.Server, error)
- func (h *Handshake) Result(address addr.Addr) (description.Server, error)
- type Insert
- func (i *Insert) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Insert
- func (i *Insert) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (i *Insert) Err() error
- func (i *Insert) Result() (result.Insert, error)
- func (i *Insert) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.Insert, error)
- type IsMaster
- func (im *IsMaster) Decode(wm wiremessage.WireMessage) *IsMaster
- func (im *IsMaster) Encode() (wiremessage.WireMessage, error)
- func (im *IsMaster) Err() error
- func (im *IsMaster) Result() (result.IsMaster, error)
- func (im *IsMaster) RoundTrip(ctx context.Context, rw wiremessage.ReadWriter) (result.IsMaster, error)
- type KillCursors
- func (kc *KillCursors) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *KillCursors
- func (kc *KillCursors) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (kc *KillCursors) Err() error
- func (kc *KillCursors) Result() (result.KillCursors, error)
- func (kc *KillCursors) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.KillCursors, error)
- type ListCollections
- func (lc *ListCollections) Decode(desc description.SelectedServer, cb CursorBuilder, wm wiremessage.WireMessage) *ListCollections
- func (lc *ListCollections) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (lc *ListCollections) Err() error
- func (lc *ListCollections) Result() (Cursor, error)
- func (lc *ListCollections) RoundTrip(ctx context.Context, desc description.SelectedServer, cb CursorBuilder, ...) (Cursor, error)
- type ListDatabases
- func (ld *ListDatabases) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *ListDatabases
- func (ld *ListDatabases) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (ld *ListDatabases) Err() error
- func (ld *ListDatabases) Result() (result.ListDatabases, error)
- func (ld *ListDatabases) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.ListDatabases, error)
- type ListIndexes
- func (li *ListIndexes) Decode(desc description.SelectedServer, cb CursorBuilder, wm wiremessage.WireMessage) *ListIndexes
- func (li *ListIndexes) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (li *ListIndexes) Err() error
- func (li *ListIndexes) Result() (Cursor, error)
- func (li *ListIndexes) RoundTrip(ctx context.Context, desc description.SelectedServer, cb CursorBuilder, ...) (Cursor, error)
- type Namespace
- type QueryFailureError
- type ResponseError
- type Update
- func (u *Update) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Update
- func (u *Update) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
- func (u *Update) Err() error
- func (u *Update) Result() (result.Update, error)
- func (u *Update) RoundTrip(ctx context.Context, desc description.SelectedServer, ...) (result.Update, error)
Constants ¶
This section is empty.
Variables ¶
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") )
Functions ¶
func IsNotFound ¶
IsNotFound indicates if the error is from a namespace not being found.
Types ¶
type Aggregate ¶
type Aggregate struct { NS Namespace Pipeline *bson.Array Opts []options.AggregateOptioner ReadPref *readpref.ReadPref // contains filtered or unexported fields }
Aggregate represents the aggregate command.
The aggregate command performs an aggregation.
func (*Aggregate) Decode ¶
func (a *Aggregate) Decode(desc description.SelectedServer, cb CursorBuilder, wm wiremessage.WireMessage) *Aggregate
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 ¶
func (a *Aggregate) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*Aggregate) HasDollarOut ¶
HasDollarOut returns true if the Pipeline field contains a $out stage.
func (*Aggregate) Result ¶
Result returns the result of a decoded wire message and server description.
func (*Aggregate) RoundTrip ¶
func (a *Aggregate) RoundTrip(ctx context.Context, desc description.SelectedServer, cb CursorBuilder, rw wiremessage.ReadWriter) (Cursor, error)
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) Result ¶
Result returns the result of a decoded wire message and server description.
func (*BuildInfo) RoundTrip ¶
func (bi *BuildInfo) RoundTrip(ctx context.Context, rw wiremessage.ReadWriter) (result.BuildInfo, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type Command ¶
type Command struct { DB string Command interface{} ReadPref *readpref.ReadPref // contains filtered or unexported fields }
Command represents a generic database command.
This can be used to send arbitrary commands to the database, e.g. runCommand.
func (*Command) Decode ¶
func (c *Command) Decode(_ description.SelectedServer, wm wiremessage.WireMessage) *Command
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 (*Command) Encode ¶
func (c *Command) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*Command) Result ¶
Result returns the result of a decoded wire message and server description.
func (*Command) RoundTrip ¶
func (c *Command) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (bson.Reader, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type Count ¶
type Count struct { NS Namespace Query *bson.Document Opts []options.CountOptioner ReadPref *readpref.ReadPref // 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 ¶
func (c *Count) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Count
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 ¶
func (c *Count) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*Count) RoundTrip ¶
func (c *Count) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (int64, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type CreateIndexes ¶
type CreateIndexes struct { NS Namespace Indexes *bson.Array Opts []options.CreateIndexesOptioner // contains filtered or unexported fields }
CreateIndexes represents the createIndexes command.
The createIndexes command creates indexes for a namespace.
func (*CreateIndexes) Decode ¶
func (ci *CreateIndexes) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *CreateIndexes
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 ¶
func (ci *CreateIndexes) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
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 ¶
func (ci *CreateIndexes) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.CreateIndexes, error)
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.Reader, 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.Reader, ...options.CursorOptioner) (Cursor, error)
}
CursorBuilder is a type that can build a Cursor.
type Delete ¶
type Delete struct { NS Namespace Deletes []*bson.Document Opts []options.DeleteOptioner // 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 ¶
func (d *Delete) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Delete
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 ¶
func (d *Delete) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*Delete) RoundTrip ¶
func (d *Delete) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.Delete, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type Distinct ¶
type Distinct struct { NS Namespace Field string Query *bson.Document Opts []options.DistinctOptioner ReadPref *readpref.ReadPref // 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 ¶
func (d *Distinct) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Distinct
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 ¶
func (d *Distinct) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*Distinct) Result ¶
Result returns the result of a decoded wire message and server description.
func (*Distinct) RoundTrip ¶
func (d *Distinct) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.Distinct, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type DropCollection ¶ added in v0.0.4
type DropCollection struct { DB string Collection string // contains filtered or unexported fields }
DropCollection represents the drop command.
The dropCollections command drops collection for a database.
func (*DropCollection) Decode ¶ added in v0.0.4
func (di *DropCollection) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *DropCollection
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 ¶ added in v0.0.4
func (di *DropCollection) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*DropCollection) Err ¶ added in v0.0.4
func (di *DropCollection) Err() error
Err returns the error set on this command.
func (*DropCollection) Result ¶ added in v0.0.4
func (di *DropCollection) Result() (bson.Reader, error)
Result returns the result of a decoded wire message and server description.
func (*DropCollection) RoundTrip ¶ added in v0.0.4
func (di *DropCollection) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (bson.Reader, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type DropDatabase ¶ added in v0.0.4
type DropDatabase struct { DB string // contains filtered or unexported fields }
DropDatabase represents the DropDatabase command.
The DropDatabases command drops database.
func (*DropDatabase) Decode ¶ added in v0.0.4
func (dd *DropDatabase) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *DropDatabase
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 ¶ added in v0.0.4
func (dd *DropDatabase) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*DropDatabase) Err ¶ added in v0.0.4
func (dd *DropDatabase) Err() error
Err returns the error set on this command.
func (*DropDatabase) Result ¶ added in v0.0.4
func (dd *DropDatabase) Result() (bson.Reader, error)
Result returns the result of a decoded wire message and server description.
func (*DropDatabase) RoundTrip ¶ added in v0.0.4
func (dd *DropDatabase) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (bson.Reader, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type DropIndexes ¶
type DropIndexes struct { NS Namespace Index string Opts []options.DropIndexesOptioner // contains filtered or unexported fields }
DropIndexes represents the dropIndexes command.
The dropIndexes command drops indexes for a namespace.
func (*DropIndexes) Decode ¶
func (di *DropIndexes) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *DropIndexes
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 ¶
func (di *DropIndexes) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
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.Reader, error)
Result returns the result of a decoded wire message and server description.
func (*DropIndexes) RoundTrip ¶
func (di *DropIndexes) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (bson.Reader, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type Find ¶
type Find struct { NS Namespace Filter *bson.Document Opts []options.FindOptioner ReadPref *readpref.ReadPref // 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 ¶
func (f *Find) Decode(desc description.SelectedServer, cb CursorBuilder, wm wiremessage.WireMessage) *Find
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 ¶
func (f *Find) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*Find) RoundTrip ¶
func (f *Find) RoundTrip(ctx context.Context, desc description.SelectedServer, cb CursorBuilder, rw wiremessage.ReadWriter) (Cursor, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type FindOneAndDelete ¶
type FindOneAndDelete struct { NS Namespace Query *bson.Document Opts []options.FindOneAndDeleteOptioner // 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 ¶
func (f *FindOneAndDelete) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *FindOneAndDelete
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 ¶
func (f *FindOneAndDelete) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
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 ¶
func (f *FindOneAndDelete) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.FindAndModify, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type FindOneAndReplace ¶
type FindOneAndReplace struct { NS Namespace Query *bson.Document Replacement *bson.Document Opts []options.FindOneAndReplaceOptioner // contains filtered or unexported fields }
FindOneAndReplace represents the findOneAndReplace operation.
The findOneAndReplace command modifies and returns a single document.
func (*FindOneAndReplace) Decode ¶
func (f *FindOneAndReplace) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *FindOneAndReplace
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 ¶
func (f *FindOneAndReplace) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
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 ¶
func (f *FindOneAndReplace) Result() (result.FindAndModify, error)
Result returns the result of a decoded wire message and server description.
func (*FindOneAndReplace) RoundTrip ¶
func (f *FindOneAndReplace) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.FindAndModify, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type FindOneAndUpdate ¶
type FindOneAndUpdate struct { NS Namespace Query *bson.Document Update *bson.Document Opts []options.FindOneAndUpdateOptioner // contains filtered or unexported fields }
FindOneAndUpdate represents the findOneAndUpdate operation.
The findOneAndUpdate command modifies and returns a single document.
func (*FindOneAndUpdate) Decode ¶
func (f *FindOneAndUpdate) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *FindOneAndUpdate
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 ¶
func (f *FindOneAndUpdate) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
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 ¶
func (f *FindOneAndUpdate) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.FindAndModify, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type GetLastError ¶
type GetLastError struct {
// 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 ¶
func (gle *GetLastError) Decode(wm wiremessage.WireMessage) *GetLastError
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 ¶
func (gle *GetLastError) RoundTrip(ctx context.Context, rw wiremessage.ReadWriter) (result.GetLastError, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type GetMore ¶
type GetMore struct { ID int64 NS Namespace Opts []options.CursorOptioner // contains filtered or unexported fields }
GetMore represents the getMore command.
The getMore command retrieves additional documents from a cursor.
func (*GetMore) Decode ¶
func (gm *GetMore) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *GetMore
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 ¶
func (gm *GetMore) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*GetMore) Result ¶
Result returns the result of a decoded wire message and server description.
func (*GetMore) RoundTrip ¶
func (gm *GetMore) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (bson.Reader, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type Handshake ¶
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(wms [2]wiremessage.WireMessage) *Handshake
Decode will decode the wire messages. The order of the wire messages are expected to be an isMaster response first and a buildInfo response second. Errors during decoding are deferred until either the Result or Err methods are called.
func (*Handshake) Encode ¶
func (h *Handshake) Encode() ([2]wiremessage.WireMessage, error)
Encode will encode the handshake commands into two wire messages. The wire messages are ordered with the isMaster command first and the buildInfo command second.
func (*Handshake) Handshake ¶
func (h *Handshake) Handshake(ctx context.Context, address addr.Addr, rw wiremessage.ReadWriter) (description.Server, error)
Handshake implements the connection.Handshaker interface. It is identical to the RoundTrip methods on other types in this package. It will execute the isMaster and buildInfo commands, using pipelining to enable a single roundtrip.
type Insert ¶
type Insert struct { NS Namespace Docs []*bson.Document Opts []options.InsertOptioner // 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 ¶
func (i *Insert) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Insert
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 ¶
func (i *Insert) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*Insert) RoundTrip ¶
func (i *Insert) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.Insert, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type IsMaster ¶
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) Result ¶
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 ¶
KillCursors represents the killCursors command.
The killCursors command kills a set of cursors.
func (*KillCursors) Decode ¶
func (kc *KillCursors) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *KillCursors
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 ¶
func (kc *KillCursors) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
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 ¶
func (kc *KillCursors) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.KillCursors, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type ListCollections ¶
type ListCollections struct { DB string Filter *bson.Document Opts []options.ListCollectionsOptioner // contains filtered or unexported fields }
ListCollections represents the listCollections command.
The listCollections command lists the collections in a database.
func (*ListCollections) Decode ¶
func (lc *ListCollections) Decode(desc description.SelectedServer, cb CursorBuilder, wm wiremessage.WireMessage) *ListCollections
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 (*ListCollections) Encode ¶
func (lc *ListCollections) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
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 ¶
func (lc *ListCollections) RoundTrip(ctx context.Context, desc description.SelectedServer, cb CursorBuilder, rw wiremessage.ReadWriter) (Cursor, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type ListDatabases ¶
type ListDatabases struct { Filter *bson.Document Opts []options.ListDatabasesOptioner // contains filtered or unexported fields }
ListDatabases represents the listDatabases command.
The listDatabases command lists the databases in a MongoDB deployment.
func (*ListDatabases) Decode ¶
func (ld *ListDatabases) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *ListDatabases
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 ¶
func (ld *ListDatabases) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
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 ¶
func (ld *ListDatabases) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.ListDatabases, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type ListIndexes ¶
type ListIndexes struct { NS Namespace Opts []options.ListIndexesOptioner // contains filtered or unexported fields }
ListIndexes represents the listIndexes command.
The listIndexes command lists the indexes for a namespace.
func (*ListIndexes) Decode ¶
func (li *ListIndexes) Decode(desc description.SelectedServer, cb CursorBuilder, wm wiremessage.WireMessage) *ListIndexes
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 (*ListIndexes) Encode ¶
func (li *ListIndexes) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
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 ¶
func (li *ListIndexes) RoundTrip(ctx context.Context, desc description.SelectedServer, cb CursorBuilder, rw wiremessage.ReadWriter) (Cursor, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
type Namespace ¶
Namespace encapsulates a database and collection name, which together uniquely identifies a collection within a MongoDB cluster.
func NewNamespace ¶
NewNamespace returns a new Namespace for the given database and collection.
func ParseNamespace ¶
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.
type QueryFailureError ¶
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 ResponseError ¶
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 Update ¶
type Update struct { NS Namespace Docs []*bson.Document Opts []options.UpdateOptioner // contains filtered or unexported fields }
Update represents the update command.
The update command updates a set of documents with the database.
func (*Update) Decode ¶
func (u *Update) Decode(desc description.SelectedServer, wm wiremessage.WireMessage) *Update
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 ¶
func (u *Update) Encode(desc description.SelectedServer) (wiremessage.WireMessage, error)
Encode will encode this command into a wire message for the given server description.
func (*Update) RoundTrip ¶
func (u *Update) RoundTrip(ctx context.Context, desc description.SelectedServer, rw wiremessage.ReadWriter) (result.Update, error)
RoundTrip handles the execution of this command using the provided wiremessage.ReadWriter.
Source Files ¶
- aggregate.go
- buildinfo.go
- command.go
- count.go
- create_indexes.go
- cursor.go
- delete.go
- distinct.go
- doc.go
- drop_collection.go
- drop_database.go
- drop_indexes.go
- errors.go
- find.go
- find_and_modify.go
- find_one_delete.go
- find_one_replace.go
- find_one_update.go
- get_more.go
- getlasterror.go
- handshake.go
- insert.go
- ismaster.go
- kill_cursors.go
- list_collections.go
- list_databases.go
- list_indexes.go
- namespace.go
- opreply.go
- update.go