旧操作码
本页描述了不再由 MongoDB 支持的旧操作码。这些旧操作码自 MongoDB 5.0 起已弃用,自 MongoDB 5.1 起不再支持。
自 MongoDB 5.0 起弃用。
自 MongoDB 5.1 起不再支持。
从 MongoDB 5.1 开始,OP_MSG 和 OP_COMPRESSED 是发送请求到 MongoDB 服务器的唯一支持的操作码。
OP_DELETE
OP_DELETE消息用于从集合中删除一个或多个文档。OP_DELETE消息的格式为:
struct { MsgHeader header; // standard message header int32 ZERO; // 0 - reserved for future use cstring fullCollectionName; // "dbname.collectionname" int32 flags; // bit values - see below for details. document selector; // query object. See below for details. }
字段 | 描述 |
---|---|
header | 消息头部。见标准消息头部。 |
ZERO | 整数值为0。保留供将来使用。 |
fullCollectionName | 完整的集合名称,特别是它的命名空间。命名空间是数据库名称和集合名称的连接,使用点(.)进行连接。例如,对于数据库名称为 test 和集合名称为contacts 的情况,完整的集合名称为test.contacts 。 |
flags | 操作的操作标志位值:位值对应以下内容
|
selector | BSON文档,表示用于选择要删除的文档的查询。选择器包含一个或多个元素,所有这些元素都必须匹配,才能从集合中删除文档。 |
没有对OP_DELETE消息的响应。
OP_GET_MORE
OP_GET_MORE消息用于查询集合中的文档。OP_GET_MORE消息的格式为:
struct { MsgHeader header; // standard message header int32 ZERO; // 0 - reserved for future use cstring fullCollectionName; // "dbname.collectionname" int32 numberToReturn; // number of documents to return int64 cursorID; // cursorID from the OP_REPLY }
字段 | 描述 |
---|---|
header | 消息头部。见标准消息头部。 |
ZERO | 整数值为0。保留供将来使用。 |
fullCollectionName | 完整的集合名称,特别是它的命名空间。命名空间是数据库名称和集合名称的连接,使用点(.)进行连接。例如,对于数据库名称为 test 和集合名称为contacts 的情况,完整的集合名称为test.contacts 。 |
numberToReturn | 限制第一个OP_REPLY 消息对查询的响应。然而,如果返回的结果数量超过 如果
|
cursorID | 游标标识符,来自 OP_REPLY。这必须是数据库中返回的值。 |
数据库将用 OP_REPLY 消息响应 OP_GET_MORE 消息。
OP_INSERT
OP_INSERT 消息用于将一个或多个文档插入到集合中。OP_INSERT 消息的格式是
struct { MsgHeader header; // standard message header int32 flags; // bit values - see below cstring fullCollectionName; // "dbname.collectionname" document* documents; // one or more documents to insert into the collection }
字段 | 描述 |
---|---|
header | 消息头部。见标准消息头部。 |
flags | 操作的操作标志位值:位值对应以下内容
|
fullCollectionName | 完整的集合名称,特别是它的命名空间。命名空间是数据库名称和集合名称的连接,使用点(.)进行连接。例如,对于数据库名称为 test 和集合名称为contacts 的情况,完整的集合名称为test.contacts 。 |
documents | 要插入到集合中的一个或多个文档。如果有多个,它们将按顺序写入套接字,一个接一个。 |
对于 OP_INSERT 消息没有响应。
OP_KILL_CURSORS
OP_KILL_CURSORS 消息用于关闭数据库中的活动游标。这是确保在查询结束时回收数据库资源所必需的。OP_KILL_CURSORS 消息的格式是
struct { MsgHeader header; // standard message header int32 ZERO; // 0 - reserved for future use int32 numberOfCursorIDs; // number of cursorIDs in message int64* cursorIDs; // sequence of cursorIDs to close }
字段 | 描述 |
---|---|
header | 消息头部。见标准消息头部。 |
ZERO | 整数值为0。保留供将来使用。 |
numberOfCursorIDs | 消息中cursor IDs的数量。 |
cursorIDs | "要关闭的cursor IDs的数组。如果有多个,它们将按顺序写入套接字,一个接一个。 |
如果一个cursor被读取到耗尽(读取到OP_QUERY或OP_GET_MORE返回cursor id为零),则无需杀死该cursor。
OP_QUERY
OP_QUERY消息用于在集合中查询数据库文档。OP_QUERY消息的格式为
struct OP_QUERY { MsgHeader header; // standard message header int32 flags; // bit values 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. }
字段 | 描述 | |
---|---|---|
header | 消息头部。见标准消息头部。 | |
flags | 操作的操作标志位值:位值对应以下内容
| |
fullCollectionName | 完整的集合名称,特别是它的命名空间。命名空间是数据库名称和集合名称的连接,使用点(.)进行连接。例如,对于数据库名称为 test 和集合名称为contacts 的情况,完整的集合名称为test.contacts 。 | |
numberToSkip | 设置要跳过的文档数量 - 从结果数据集的第一份文档开始 - 当返回查询结果时。 | |
numberToReturn | 限制查询的第一个OP_REPLY消息中的文档数量。然而,如果结果多于 如果
| |
查询 | 表示查询的BSON文档。查询包含一个或多个元素,所有这些元素都必须匹配才能将文档包含在结果集中。可能的元素包括 $query 、$orderby 、$hint 和$explain 。 | |
returnFieldsSelector | 可选。限制返回文档的字段的BSON文档。`returnFieldsSelector`包含一个或多个元素,每个元素都是应返回的字段的名称,以及整数值`1`。在JSON表示法中,用于限制字段`a`、`b`和`c`的`returnFieldsSelector`将是
|
数据库将用OP_REPLY消息响应OP_QUERY消息。
注意
MongoDB 5.1移除了对OP_QUERY
查找操作和OP_QUERY
命令的支持。作为一个例外,OP_QUERY
仍支持在连接握手过程中运行hello
和isMaster
命令。
OP_REPLY
OP_REPLY
消息是由数据库在响应OP_QUERY或OP_GET_MORE消息时发送的。OP_REPLY消息的格式是
struct { MsgHeader header; // standard message header int32 responseFlags; // bit values - see details below int64 cursorID; // cursor ID if client needs to do get more's int32 startingFrom; // where in the cursor this reply is starting int32 numberReturned; // number of documents in the reply document* documents; // documents }
字段 | 描述 |
---|---|
header | 消息头部。见标准消息头部。 |
responseFlags | 操作的操作标志位值:位值对应以下内容
|
cursorID | 此 OP_REPLY 是其一部分的 cursorID 。如果查询的结果集适合一个 OP_REPLY 消息,则 cursorID 将为 0。此 cursorID 必须用于任何用于获取更多数据的 OP_GET_MORE 消息,并且也必须通过 OP_KILL_CURSORS 消息由客户端关闭。 |
startingFrom | 游标中的起始位置。 |
numberReturned | 回复中的文档数。 |
documents | 返回的文档。 |
OP_UPDATE
OP_UPDATE 消息用于在集合中更新文档。OP_UPDATE 消息的格式如下
struct OP_UPDATE { MsgHeader header; // standard message header int32 ZERO; // 0 - reserved for future use cstring fullCollectionName; // "dbname.collectionname" int32 flags; // bit values. see below document selector; // the query to select the document document update; // specification of the update to perform }
字段 | 描述 |
---|---|
header | 消息头部。见标准消息头部。 |
ZERO | 整数值为0。保留供将来使用。 |
fullCollectionName | 完整的集合名称,特别是它的命名空间。命名空间是数据库名称和集合名称的连接,使用点(.)进行连接。例如,对于数据库名称为 test 和集合名称为contacts 的情况,完整的集合名称为test.contacts 。 |
flags | 操作的操作标志位值:位值对应以下内容
|
selector | 指定要更新的文档的选择查询的 BSON 文档。 |
update | 指定要执行的更新的 BSON 文档。有关指定更新的信息,请参阅更新操作文档。 |
对于 OP_UPDATE 消息没有响应。