wire / wire-format / mongodb-wire

MongoDB wire protocol (OP_MSG)

MongoDB's wire protocol (since MongoDB 3.6) uses OP_MSG as the primary message type. An OP_MSG: header (standard message header: length, requestID, responseTo, opCode=2013), then flags (4 bytes), then sections. Sections: type 0 (body, a single BSON document) or type 1 (document sequence, with identifier + documents). Checksum (optional, 4 bytes CRC32C) follows.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: MongoDB wire protocol (OP_MSG)

wire format

spec: MongoDB wire protocol

MongoDB's wire protocol (since MongoDB 3.6) uses OP_MSG as the primary message type. An OP_MSG: header (standard message header: length, requestID, responseTo, opCode=2013), then flags (4 bytes), then sections. Sections: type 0 (body, a single BSON document) or type 1 (document sequence, with identifier + documents). Checksum (optional, 4 bytes CRC32C) follows.

fieldsizemeaning
Message length4 bytes (int32)Total message size including header.
Request ID4 bytes (int32)Client-assigned request identifier.
Response to4 bytes (int32)Request ID being responded to (0 for requests).
Op code4 bytes (int32)2013 = OP_MSG (the modern message type).
Flags4 bytes (uint32)Bit 0 = checksumPresent, bit 1 = moreToCome, bit 16 = exhaustAllowed.
Section type1 byte0 = body (single BSON document), 1 = document sequence (identifier + count + documents).
BodyvariableA single BSON document containing the command and its arguments.
Checksum4 bytesCRC32C of the message (if checksumPresent flag set).

example:

4d 00 00 00 01 00 00 00 00 00 00 00 dd 07 00 00 00 00 00 00

OP_MSG header: length 77, requestID 1, responseTo 0, opCode 2013 (OP_MSG)


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/mongodb-wire or /wire-format/mongodb-wire.json