Documentation ¶
Index ¶
- func AllRequestTypeNames() []string
- func Encode(w io.Writer, r Response, reqID int32, replyType ReplyType) error
- type CommandRequest
- type DeleteRequest
- type DeleteTarget
- type ErrorCode
- type FindAndDeleteRequest
- type FindAndUpdateRequest
- type GetMoreRequest
- type InsertFlag
- type InsertRequest
- type KillCursorsRequest
- type NamespacedCollection
- type QueryFlag
- type QueryRequest
- type RPCHeader
- type ReplyType
- type Request
- type RequestInfo
- type RequestType
- type Response
- type ResponseFlag
- type ServerError
- type UnknownRequest
- type UpdateFlag
- type UpdateRequest
- type UpdateTarget
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllRequestTypeNames ¶
func AllRequestTypeNames() []string
AllRequestTypeNames returns a lexicographically sorted list with all request types supported by the decoder.
Types ¶
type CommandRequest ¶
type CommandRequest struct { RequestInfo Collection NamespacedCollection Command string Args bson.M }
CommandRequest represents a mongo command sent by a mongo client.
type DeleteRequest ¶
type DeleteRequest struct { RequestInfo Collection NamespacedCollection Deletes []DeleteTarget }
DeleteRequest represents a request to delete a set of documents.
type DeleteTarget ¶
DeleteTarget represents a single delete operation.
type ErrorCode ¶
type ErrorCode int
ErrorCode describes the type of error messages returned by a mongo server.
const ( CodeNoReplicationEnabled ErrorCode = 76 )
A common subset of the error codes returned by mongo servers. The full list can be found here: https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.yml.
type FindAndDeleteRequest ¶
type FindAndDeleteRequest struct { RequestInfo Collection NamespacedCollection // Query for matching the document to update Query bson.M // Optional sort order in case multiple documents match the query. Only // the first document will be affected by this operation. Sort bson.M // An optional selector for the fields in the returned document. FieldSelector bson.M }
FindAndDeleteRequest encapsulates the arguments for a find and delete command (issued via a call to findAndModify with remove: true). This command deletes the matched document and returns it back to the caller.
See https://docs.mongodb.com/manual/reference/command/findAndModify/#findandmodify
type FindAndUpdateRequest ¶
type FindAndUpdateRequest struct { RequestInfo Collection NamespacedCollection // Query for matching the document to update Query bson.M // Optional sort order in case multiple documents match the query. Only // the first document will be affected by this operation. Sort bson.M Update bson.M ArrayFilters []bson.M // Create the document if missing. Upsert bool // If true, return back the updated document; otherwise return the // original document before applying the update. ReturnUpdatedDoc bool // An optional selector for the fields in the returned document. FieldSelector bson.M }
FindAndUpdateRequest encapsulates the arguments for a find and replace command. This command updates the matched document and returns back either the original document or the modified document depending on the value of the ReturnUpdatedDoc flag.
See https://docs.mongodb.com/manual/reference/command/findAndModify/#findandmodify
type GetMoreRequest ¶
type GetMoreRequest struct { RequestInfo Collection NamespacedCollection NumToReturn int32 CursorID int64 }
GetMoreRequest represents a request to read additional documents off a cursor.
func (GetMoreRequest) ReplyExpected ¶
func (GetMoreRequest) ReplyExpected() bool
ReplyExpected always returns true for GetMore requests.
type InsertFlag ¶
type InsertFlag uint32
InsertFlag represents the allowed flag values for an insert request.
const ( // If set, the database will continue processing a bulk inseert request // even if an error occurs. InsertFlagContinueOnError InsertFlag = 1 << iota )
The list of supported insert flags.
type InsertRequest ¶
type InsertRequest struct { RequestInfo Collection NamespacedCollection Flags InsertFlag Inserts []bson.M }
InsertRequest represents an single or bulk document insert request.
type KillCursorsRequest ¶
type KillCursorsRequest struct { RequestInfo CursorIDs []int64 }
KillCursorsRequest represents a request to close a set of active cursors.
type NamespacedCollection ¶
NamespacedCollection encodes a namespaced collection.
func (NamespacedCollection) String ¶
func (c NamespacedCollection) String() string
String implements fmt.Stringer for NamespacedCollection.
type QueryFlag ¶
type QueryFlag uint32
QueryFlag represents the allowed flag values for a query request.
const ( // Tailable means cursor is not closed when the last data is retrieved. Rather, // the cursor marks the final object’s position. You can resume using the // cursor later, from where it was located, if more data were received. Like // any “latent cursor”, the cursor may become invalid at some point // (CursorNotFound) – for example if the final object it references were // deleted. QueryFlagTailableCursor QueryFlag // Allow query of replica slave. Normally these return an error except for namespace “local”. QueryFlagSlaveOK // Internal replication use only - driver should not set. QueryFlagOplogReplay // The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that. QueryFlagNoCursorTimeout // Use with TailableCursor. If we are at the end of the data, block for a while rather than returning no data. After a timeout period, we do return as normal. QueryFlagAwaitData // Stream the data down full blast in multiple “more” packages, on the assumption that the client will fully read all data queried. Faster when you are pulling a lot of data and know you want to pull it all down. Note: the client is not allowed to not read all the data unless it closes the connection. QueryFlagExhaust // Get partial results from a mongos if some shards are down (instead of throwing an error) QueryFlagPartial )
The list of supported query flags.
type QueryRequest ¶
type QueryRequest struct { RequestInfo Collection NamespacedCollection Flags QueryFlag NumToSkip int32 NumToReturn int32 Query bson.M Sort bson.M FieldSelector bson.M }
QueryRequest represents a search query.
type RPCHeader ¶
RPCHeader provides information about a request or response payload.
func (RPCHeader) PayloadLength ¶
PayloadLength returns the size of the request payload exluding the header.
type ReplyType ¶
type ReplyType uint8
ReplyType describes the type of expected (if any) reply for a client request.
type Request ¶
type Request interface { // Opcode returns the opcode identifying this request type. Opcode() int32 // GetType returns a string representation of this request type. GetType() RequestType // GetReplyType returns the type of reply expected for this request. GetReplyType() ReplyType // RequestID returns the unique request ID for an incoming request. RequestID() int32 }
Request represents a client request.
type RequestInfo ¶
type RequestInfo struct { // The standard RPC header used by all request and responses. Header RPCHeader // The type of this request. RequestType RequestType // The type of expected reply for this request. Depending on the request // opcode, the reply: // - can be omitted (e.g. OP_INSERT/UPDATE/DELETE/KILL_CURSORS) // - uses the OP_REPLY format (OP_QUERY, OP_GETMORE) // - uses the new OP_MSG format (for requests using OP_MSG envelopes). ReplyType ReplyType }
RequestInfo provides low-level information about a request and implements a subset of the Request interface methods. It's used as a mixin for concrete Request definitions to avoid code repetition.
func (RequestInfo) GetReplyType ¶
func (r RequestInfo) GetReplyType() ReplyType
GetReplyType returns the expected reply type for this request.
func (RequestInfo) GetType ¶
func (r RequestInfo) GetType() RequestType
GetType returns the type of this request.
func (RequestInfo) Opcode ¶
func (r RequestInfo) Opcode() int32
Opcode returns the opcode for this request.
func (RequestInfo) RequestID ¶
func (r RequestInfo) RequestID() int32
RequestID returns the unique request ID for this request.
type RequestType ¶
type RequestType string
RequestType describes the type of a client request.
const ( RequestTypeUpdate RequestType = "update" RequestTypeInsert RequestType = "insert" RequestTypeGetMore RequestType = "getMore" RequestTypeDelete RequestType = "delete" RequestTypeKillCursors RequestType = "killCursors" RequestTypeQuery RequestType = "query" RequestTypeCommand RequestType = "command" RequestTypeFindAndUpdate RequestType = "findAndUpdate" RequestTypeFindAndDelete RequestType = "findAndDelete" RequestTypeUnknown RequestType = "unknown" )
The supported request types.
type Response ¶
type Response struct { Flags ResponseFlag CursorID int64 StartingFrom int32 Documents []bson.M }
Response represents a response to a mongo client request.
type ResponseFlag ¶
type ResponseFlag uint32
ResponseFlag represents the allowed flag values for a reply message.
const ( // Set when getMore is called but the cursor id is not valid at the // server. ResponseFlagCursorNotFound ResponseFlag = 1 << iota // Set when a query failed. The reply will include a single document // with more details about the error. ResponseFlagQueryError )
The list of supported response flags.
type ServerError ¶
ServerError describes a server error with an associated status code.
func ServerErrorf ¶
func ServerErrorf(code ErrorCode, format string, args ...interface{}) ServerError
ServerErrorf creates a formatted ServerError.
func (ServerError) Error ¶
func (e ServerError) Error() string
Error returns a string representation for this error
type UnknownRequest ¶
type UnknownRequest struct { RequestInfo // The raw payload of the captured request (sans header) Payload []byte }
UnknownRequest represents a client request that the parser does not know how to decode.
type UpdateFlag ¶
type UpdateFlag uint32
UpdateFlag represents the allowed flag values for an update request.
const ( // If set, the database will insert the supplied object into the // collection if no matching document is found. UpdateFlagUpsert UpdateFlag = 1 << iota // If set, the database will update all matching objects in the // collection. Otherwise only updates first matching document. UpdateFlagMulti )
The list of supported update flags.
type UpdateRequest ¶
type UpdateRequest struct { RequestInfo Collection NamespacedCollection Updates []UpdateTarget }
UpdateRequest represents an update request.
type UpdateTarget ¶
UpdateTarget represents a single update operation.