wire / wire-format / mongodb-wire
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.
aka: MongoDB wire protocol (OP_MSG)
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.
| field | size | meaning |
|---|---|---|
| Message length | 4 bytes (int32) | Total message size including header. |
| Request ID | 4 bytes (int32) | Client-assigned request identifier. |
| Response to | 4 bytes (int32) | Request ID being responded to (0 for requests). |
| Op code | 4 bytes (int32) | 2013 = OP_MSG (the modern message type). |
| Flags | 4 bytes (uint32) | Bit 0 = checksumPresent, bit 1 = moreToCome, bit 16 = exhaustAllowed. |
| Section type | 1 byte | 0 = body (single BSON document), 1 = document sequence (identifier + count + documents). |
| Body | variable | A single BSON document containing the command and its arguments. |
| Checksum | 4 bytes | CRC32C 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)
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/mongodb-wire
or /wire-format/mongodb-wire.json