mongo通信协议
先是一个包头:
struct MsgHeader { int32 messageLength; // total message size, including this int32 requestID; // identifier for this message int32 responseTo; // requestID from the original request // (used in responses from db) int32 opCode; // request type - see table below for details }
特点:每个请求都有个id,客户端启动的时候从0开始递增
opCode表示操作类型,根据这个处理后面真正的请求
比如查询包:
struct OP_QUERY { MsgHeader header; // standard message header int32 flags; // bit vector of query options. See below for details. cstring fullCollectionName ; // "dbname.collectionname" int32 numberToSkip; // number of documents to skip int32 numberToReturn; // number of documents to return // in the first OP_REPLY batch document query; // query object. See below for details. [ document returnFieldsSelector; ] // Optional. Selector indicating the fields // to return. See below for details. }
抓包情况如下:
一目了然。
官网:https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】