Documentation
¶
Overview ¶
Package mongoproto specifies the MongoDB wire protocol
See http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/
Index ¶
- Constants
- Variables
- func CopyMessage(w io.Writer, r io.Reader) error
- func ReadDocument(r io.Reader) ([]byte, error)
- type ErrUnknownOpcode
- type MsgHeader
- type Op
- type OpCode
- type OpDelete
- type OpDeleteFlags
- type OpGetMore
- type OpInsert
- type OpInsertFlags
- type OpKillCursors
- type OpMsg
- type OpQuery
- type OpQueryFlags
- type OpRaw
- type OpReply
- type OpReplyFlags
- type OpUnknown
- type OpUpdate
- type OpUpdateFlags
Constants ¶
const ( OpCodeReply = OpCode(1) OpCodeMessage = OpCode(1000) OpCodeUpdate = OpCode(2001) OpCodeInsert = OpCode(2002) OpCodeReserved = OpCode(2003) OpCodeQuery = OpCode(2004) OpCodeGetMore = OpCode(2005) OpCodeDelete = OpCode(2006) OpCodeKillCursors = OpCode(2007) )
The full set of known request op codes: http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#request-opcodes
const (
MaxMessageSize = 48 << 20 // 48 MB
)
const MsgHeaderLen = 16 // mongo MsgHeader length in bytes
Variables ¶
var (
ErrInvalidSize = errors.New("mongoproto: got invalid document size")
)
var ErrNotMsg = fmt.Errorf("buffer is too small to be a Mongo message")
ErrNotMsg is returned if a provided buffer is too small to contain a Mongo message
Functions ¶
func CopyMessage ¶
CopyMessage copies reads & writes an entire message.
Types ¶
type ErrUnknownOpcode ¶
type ErrUnknownOpcode int
ErrUnknownOpcode is an error that represents an unrecognized opcode.
func (ErrUnknownOpcode) Error ¶
func (e ErrUnknownOpcode) Error() string
type MsgHeader ¶
type MsgHeader struct { // MessageLength is the total message size, including this header MessageLength int32 // RequestID is the identifier for this miessage RequestID int32 // ResponseTo is the RequestID of the message being responded to. used in DB responses ResponseTo int32 // OpCode is the request type, see consts above. OpCode OpCode }
MsgHeader is the mongo MessageHeader
type OpCode ¶
type OpCode int32
OpCode allow identifying the type of operation:
http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#request-opcodes
func (OpCode) HasResponse ¶
HasResponse tells us if the operation will have a response from the server.
func (OpCode) IsMutation ¶
IsMutation tells us if the operation will mutate data. These operations can be followed up by a getLastErr operation.
type OpDelete ¶
type OpDelete struct { Header MsgHeader FullCollectionName string // "dbname.collectionname" Flags OpDeleteFlags Selector *bson.D // the query to select the document(s) }
OpDelete is used to remove one or more documents from a collection. http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-delete
type OpDeleteFlags ¶
type OpDeleteFlags int32
const (
OpDeleteSingleRemove OpDeleteFlags = 1 << iota
)
type OpGetMore ¶
type OpGetMore struct { Header MsgHeader FullCollectionName string // "dbname.collectionname" NumberToReturn int32 // number of documents to return CursorID int64 // cursorID from the OpReply }
OpGetMore is used to query the database for documents in a collection. http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-get-more
type OpInsert ¶
type OpInsert struct { Header MsgHeader Flags OpInsertFlags FullCollectionName string // "dbname.collectionname" Documents [][]byte // one or more documents to insert into the collection }
OpInsert is used to insert one or more documents into a collection. http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-insert
type OpInsertFlags ¶
type OpInsertFlags int32
const (
OpInsertContinueOnError OpInsertFlags = 1 << iota
)
type OpKillCursors ¶
OpKillCursors is used to close an active cursor in the database. This is necessary to ensure that database resources are reclaimed at the end of the query. http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-kill-cursors
type OpMsg ¶
OpMsg sends a diagnostic message to the database. The database sends back a fixed response. OpMsg is Deprecated http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-msg
type OpQuery ¶
type OpQuery struct { Header MsgHeader Flags OpQueryFlags FullCollectionName string // "dbname.collectionname" NumberToSkip int32 // number of documents to skip NumberToReturn int32 // number of documents to return Query []byte // query object ReturnFieldsSelector []byte // Optional. Selector indicating the fields to return }
OpQuery is used to query the database for documents in a collection. http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-query
type OpQueryFlags ¶
type OpQueryFlags int32
const ( OpQueryTailableCursor OpQueryFlags // 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. OpQuerySlaveOk // Allow query of replica slave. Normally these return an error except for namespace “local”. OpQueryOplogReplay // Internal replication use only - driver should not set OpQueryNoCursorTimeout // The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that. OpQueryAwaitData // 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. OpQueryExhaust // 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. OpQueryPartial // Get partial results from a mongos if some shards are down (instead of throwing an error) )
type OpRaw ¶
OpRaw may be exactly the same as OpUnknown.
func OpRawFromReader ¶
OpRawFromReader reads an op without decoding it.
type OpReply ¶
type OpReply struct { Header MsgHeader Message string Flags OpReplyFlags CursorID int64 // cursor id if client needs to do get more's StartingFrom int32 // where in the cursor this reply is starting NumberReturned int32 // number of documents in the reply Documents [][]byte // documents }
OpReply is sent by the database in response to an OpQuery or OpGetMore message. http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-reply
func (*OpReply) FromReader ¶
XXX make a version of this that doesn't read the bodies
type OpReplyFlags ¶
type OpReplyFlags int32
const ( OpReplyCursorNotFound OpReplyFlags = 1 << iota // Set when getMore is called but the cursor id is not valid at the server. Returned with zero results. OpReplyQueryFailure // Set when query failed. Results consist of one document containing an “$err” field describing the failure. OpReplyShardConfigStale //Drivers should ignore this. Only mongos will ever see this set, in which case, it needs to update config from the server. OpReplyAwaitCapable //Set when the server supports the AwaitData Query option. If it doesn’t, a client should sleep a little between getMore’s of a Tailable cursor. Mongod version 1.6 supports AwaitData and thus always sets AwaitCapable. )
type OpUpdate ¶
type OpUpdate struct { Header MsgHeader FullCollectionName string // "dbname.collectionname" Flags OpUpdateFlags Selector *bson.D // the query to select the document Update *bson.D // specification of the update to perform }
OpUpdate is used to update a document in a collection. http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-update
type OpUpdateFlags ¶
type OpUpdateFlags int32
const ( OpUpdateUpsert OpUpdateFlags = 1 << iota OpUpdateMuli )