Legacy Opcodes
This page describes legacy opcodes that are no longer supported by MongoDB. 本页描述MongoDB不再支持的旧操作码。These legacy opcodes are:这些传统操作码包括:
Deprecated as of MongoDB 5.0.自MongoDB 5.0起已弃用。
Unsupported as of MongoDB 5.1.从MongoDB 5.1开始不受支持。
Starting in MongoDB 5.1, OP_MSG and OP_COMPRESSED are the only supported opcodes to send requests to a MongoDB server.
OP_DELETE
The OP_DELETE message is used to remove one or more documents from a collection. OP_DELETE消息用于从集合中删除一个或多个文档。The format of the OP_DELETE message is:OP_DELETE消息的格式为:
struct {
MsgHeader header;
int32
ZERO;
cstring fullCollectionName;
int32
flags;
document selector;
}
Field字段 | Description描述 |
header | Message header. 消息标题。See Standard Message Header.请参见标准消息标题。 |
ZERO | Integer value of 0. 整数值为0。Reserved for future use.保留供将来使用。 |
fullCollectionName | The full collection name, specifically its namespace. 完整的集合名称,特别是其命名空间。The namespace is the concatenation of the database name with the collection name, using a . for the concatenation. 命名空间是数据库名称与集合名称的连接,使用. 作为连接。For example, for the database test and the collection contacts , the full collection name is test.contacts .例如,对于数据库test 和集合contacts ,集合的全名为test.contacts 。
|
flags | Bit values for the operation: The bit values correspond to the following:操作的位值:位值对应于以下内容:
0 corresponds to SingleRemove. 对应于SingleRemove。If set, the database will remove only the first matching document in the collection. 如果设置,数据库将仅删除集合中的第一个匹配文档。Otherwise all matching documents will be removed.否则,将删除所有匹配的文档。
1 -31 are reserved. 保留。Must be set to 0.必须设置为0。
|
selector | BSON document that represent the query used to select the documents to be removed. BSON文档,表示用于选择要删除的文档的查询。The selector contains one or more elements, all of which must match for a document to be removed from the collection.选择器包含一个或多个元素,所有元素都必须匹配才能从集合中删除文档。
|
There is no response to an OP_DELETE message.OP_DELETE消息没有响应。
OP_GET_MORE
The OP_GET_MORE message is used to query the database for documents in a collection. OP_GET_MORE消息用于在数据库中查询集合中的文档。The format of the OP_GET_MORE message is:OP_GET_MORE消息的格式为:
struct {
MsgHeader header;
int32
ZERO;
cstring fullCollectionName;
int32
numberToReturn;
int64
cursorID;
}
Field字段 | Description描述 |
header | Message header. 消息标题。See Standard Message Header.请参见标准消息标题。 |
ZERO | Integer value of 0. 整数值为0。 Reserved for future use.保留供将来使用。 |
fullCollectionName | The full collection name, specifically its namespace. 完整的集合名称,特别是其命名空间。The namespace is the concatenation of the database name with the collection name, using a . for the concatenation. 命名空间是数据库名称与集合名称的连接,使用. 作为连接。For example, for the database test and the collection contacts , the full collection name is test.contacts .例如,对于数据库test 和集合contacts ,集合的全名为test.contacts 。
|
numberToReturn | Limits the number of documents in the first OP_REPLY message to the query. 限制查询的第一条OP_REPLY消息中的文档数。However, the database will still establish a cursor and return the cursorID to the client if there are more results than numberToReturn . 但是,如果结果多于numberToReturn ,数据库仍将建立一个游标并将cursorID 返回给客户端。If the client driver offers 'limit' functionality (like the SQL LIMIT keyword), then it is up to the client driver to ensure that no more than the specified number of document are returned to the calling application.如果客户端驱动程序提供“限制”功能(如SQL limit关键字),则由客户端驱动程序确保返回给调用应用程序的文档不超过指定数量。
If numberToReturn is:如果numberToReturn 为:
0 , the database uses the default return size.,数据库使用默认的返回大小。
Negative, the database returns that number and close the cursor. 否,数据库返回该数字并关闭游标。No further results for that query can be fetched.无法获取该查询的进一步结果。
1 , the server will treat the value as -1 (closing the cursor automatically).,服务器会将该值视为-1 (自动关闭游标)。
|
cursorID | Cursor identifier that came in the OP_REPLY. OP_REPLY中的游标标识符。This must be the value that came from the database.这必须是来自数据库的值。
|
The database will respond to an OP_GET_MORE message with an OP_REPLY message.数据库将用OP_REPLY消息响应OP_GET_MORE消息。
OP_INSERT
The OP_INSERT message is used to insert one or more documents into a collection. OP_INSERT消息用于将一个或多个文档插入到集合中。The format of the OP_INSERT message is:OP_INSERT消息的格式为:
struct {
MsgHeader header;
int32
flags;
cstring fullCollectionName;
document* documents;
}
Field字段 | Description描述 |
header | Message header. 消息标题。See Standard Message Header.请参见标准消息标题。 |
flags | Bit values for the operation: The bit values correspond to the following:操作的位值:位值对应于以下内容:
0 corresponds to ContinueOnError. 对应于ContinueOnError。If set, the database will not stop processing a bulk insert if one fails (for example, due to duplicate IDs). 如果设置了,则如果大容量插入失败(例如,由于重复ID),数据库将不会停止处理大容量插入。This makes bulk insert behave similarly to a series of single inserts, except lastError will be set if any insert fails, not just the last one. 这使得大容量插入的行为类似于一系列单个插入,但如果任何插入失败,将设置lastError,而不仅仅是最后一次。If multiple errors occur, only the most recent will be reported by getLastError.如果发生多个错误,getLastError将只报告最近的错误。
1 -31 are reserved. Must be set to 0.保留。必须设置为0。
|
fullCollectionName | The full collection name, specifically its namespace. 完整的集合名称,特别是其命名空间。The namespace is the concatenation of the database name with the collection name, using a . for the concatenation. 命名空间是数据库名称与集合名称的连接,使用. 作为连接。For example, for the database test and the collection contacts , the full collection name is test.contacts .例如,对于数据库test 和集合contacts ,集合的全名为test.contacts 。
|
documents | One or more documents to insert into the collection. 要插入到集合中的一个或多个文档。If there are more than one, they are written to the socket in sequence, one after another.如果有多个,它们将依次写入套接字。
|
There is no response to an OP_INSERT message.OP_INSERT消息没有响应。
OP_KILL_CURSORS
The OP_KILL_CURSORS message is used to close an active cursor in the database. OP_KILL_CURSORS消息用于关闭数据库中的活动游标。This is necessary to ensure that database resources are reclaimed at the end of the query. 这对于确保在查询结束时回收数据库资源是必要的。The format of the OP_KILL_CURSORS message is: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
}
Field字段 | Description描述 |
header | Message header. 消息标题。See Standard Message Header.请参见标准消息标题。 |
ZERO | Integer value of 0. 整数值为0。Reserved for future use.保留供将来使用。 |
numberOfCursorIDs | The number of cursor IDs that are in the message.消息中的游标ID数。 |
cursorIDs | "Array" of cursor IDs to be closed. 要关闭的游标ID的“数组”。If there are more than one, they are written to the socket in sequence, one after another.如果有多个,它们将依次写入套接字。
|
If a cursor is read until exhausted (read until OP_QUERY or OP_GET_MORE returns zero for the cursor id), there is no need to kill the cursor.如果游标被读取直到耗尽(读取直到OP_QUERY或OP_GET_MORE为游标id返回零),则无需终止游标。
OP_QUERY
The OP_QUERY message is used to query the database for documents in a collection. OP_QUERY消息用于在数据库中查询集合中的文档。The format of the OP_QUERY message is:OP_QUERY消息的格式为:
struct OP_QUERY {
MsgHeader header;
int32
flags;
cstring fullCollectionName ;
int32
numberToSkip;
int32
numberToReturn;
document query;
[ document returnFieldsSelector; ]
}
Field字段 | Description描述 |
header | Message header. 消息标题。See Standard Message Header.请参见标准消息标题。 |
flags | Bit values for the operation: The bit values correspond to the following:操作的位值:位值对应于以下内容:
0 is reserved. Must be set to 0.
1 corresponds to TailableCursor. 对应于TailableCursor。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.与任何潜在的游标一样,游标可能在某个点(CursorNotFound)失效,例如,如果它引用的最后一个对象被删除。
2 corresponds to SlaveOk. 对应于SlaveOk。Allow query of replica slave. Normally these return an error except for namespace "local".允许查询副本从机。通常,除了命名空间“local”之外,它们都会返回一个错误。
3 corresponds to OplogReplay. 对应于OplogReplay。Starting in MongoDB 4.4, you need not specify this flag because the optimization automatically happens for eligible queries on the oplog. 从MongoDB 4.4开始,您无需指定此标志,因为优化会自动针对oplog上符合条件的查询进行。See oplogReplay for more information.有关详细信息,请参阅oplogReplay。
4 corresponds to NoCursorTimeout. 对应于NoCursorTimeout。The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. 服务器通常会在一段非活动时间(10分钟)后超时空闲游标,以防止内存过度使用。Set this option to prevent that.设置此选项可防止这种情况发生。
5 corresponds to AwaitData. Use with TailableCursor. 对应于AwaitData。与TailableCursor一起使用。If the cursor is at the end of the data, block for a while rather than returning no data. 如果游标位于数据的末尾,请阻塞一段时间,而不是不返回任何数据。After a timeout period, the server returns as normal.超时后,服务器恢复正常。
6 corresponds to Exhaust. 对应于排气。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.注意:除非关闭连接,否则不允许客户端读取所有数据。
7 corresponds to Partial. 对应于部分。Get partial results from a mongos if some shards are down (instead of throwing an error)如果某些分片关闭,则从mongos 获取部分结果(而不是抛出错误)
8 -31 are reserved. 保留。Must be set to 0.必须设置为0。
|
fullCollectionName | The full collection name, specifically its namespace. 完整的集合名称,特别是其命名空间。The namespace is the concatenation of the database name with the collection name, using a . for the concatenation. 命名空间是数据库名称与集合名称的连接,使用. 作为连接。For example, for the database test and the collection contacts , the full collection name is test.contacts .例如,对于数据库test 和集合contacts ,集合的全名为test.contacts 。
|
numberToSkip | Sets the number of documents to omit - starting from the first document in the resulting dataset - when returning the result of the query.设置返回查询结果时要忽略的文档数(从结果数据集中的第一个文档开始)。 |
numberToReturn | Limits the number of documents in the first OP_REPLY message to the query. However, the database will still establish a cursor and return the cursorID to the client if there are more results than numberToReturn . If the client driver offers 'limit' functionality (like the SQL LIMIT keyword), then it is up to the client driver to ensure that no more than the specified number of document are returned to the calling application.如果客户端驱动程序提供“限制”功能(如SQL limit关键字),则由客户端驱动程序确保返回给调用应用程序的文档不超过指定数量。
If numberToReturn is:如果numberToReturn 为:
0 , the database uses the default return size.,数据库使用默认的返回大小。
Negative, the database returns that number and close the cursor. 否,数据库返回该数字并关闭游标。No further results for that query can be fetched.无法获取该查询的进一步结果。
1 , the server will treat the value as -1 (closing the cursor automatically).,服务器会将该值视为-1 (自动关闭游标)。
|
query | BSON document that represents the query. 表示查询的BSON文档。The query contains one or more elements, all of which must match for a document to be included in the result set. 查询包含一个或多个元素,所有元素都必须匹配才能将文档包含在结果集中。Possible elements include $query , $orderby , $hint , and $explain .可能的元素包括$query 、$orderby 、$hint 和$explain 。
|
returnFieldsSelector | Optional. 可选。BSON document that limits the fields in the returned documents. 限制返回文档中字段的BSON文档。The returnFieldsSelector contains one or more elements, each of which is the name of a field that should be returned, and and the integer value 1 . returnFieldsSelector 包含一个或多个元素,每个元素都是应该返回的字段的名称,以及整数值1 。In JSON notation, a returnFieldsSelector to limit to the fields a , b and c would be:在JSON表示法中,限制为字段a 、b 和c 的returnFieldsSelector 为:
{ a : 1, b : 1, c : 1}
|
The database will respond to an OP_QUERY message with an OP_REPLY message.数据库将用OP_REPLY消息响应OP_QUERY消息。
Note注意
MongoDB 5.1 removes support for both OP_QUERY
find operations and OP_QUERY
commands. As an exception, OP_QUERY
is still supported for running the hello
and isMaster
commands as part of the connection handshake.
OP_REPLY
The OP_REPLY
message is sent by the database in response to an OP_QUERY or OP_GET_MORE message. The format of an OP_REPLY message is:
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
}
Field字段 | Description描述 |
header | Message header. See Standard Message Header. |
responseFlags | Bit values for the operation: The bit values correspond to the following:操作的位值:位值对应于以下内容:
0 corresponds to CursorNotFound. Is set when getMore is called but the cursor id is not valid at the server. Returned with zero results.
1 corresponds to QueryFailure. Is set when query failed. Results consist of one document containing an "$err" field describing the failure.
2 corresponds to ShardConfigStale. Drivers should ignore this. Only mongos will ever see this set, in which case, it needs to update config from the server.
3 corresponds to AwaitCapable. Is 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.
4 -31 are reserved. Ignore.
|
cursorID | The cursorID that this OP_REPLY is a part of. In the event that the result set of the query fits into one OP_REPLY message, cursorID will be 0. This cursorID must be used in any OP_GET_MORE messages used to get more data, and also must be closed by the client when no longer needed via a OP_KILL_CURSORS message.
|
startingFrom | Starting position in the cursor.游标中的起始位置。 |
numberReturned | Number of documents in the reply. |
documents | Returned documents.退回的文件。 |
OP_UPDATE
The OP_UPDATE message is used to update a document in a collection. OP_UPDATE消息用于更新集合中的文档。The format of a OP_UPDATE message is the following:OP_UPDATE消息的格式如下:
struct OP_UPDATE {
MsgHeader header;
int32
ZERO;
cstring fullCollectionName;
int32
flags;
document selector;
document update;
}
Field字段 | Description描述 |
header | Message header. See Standard Message Header. |
ZERO | Integer value of 0. 整数值为0。Reserved for future use.保留供将来使用。 |
fullCollectionName | The full collection name, specifically its namespace. 完整的集合名称,特别是其命名空间。The namespace is the concatenation of the database name with the collection name, using a . for the concatenation. 命名空间是数据库名称与集合名称的连接,使用. 作为连接。For example, for the database test and the collection contacts , the full collection name is test.contacts .例如,对于数据库test 和集合contacts ,集合的全名为test.contacts 。
|
flags | Bit values for the operation: The bit values correspond to the following:操作的位值:位值对应于以下内容:
0 corresponds to Upsert. 对应于Upsert。If set, the database will insert the supplied object into the collection if no matching document is found.如果设置了,如果找不到匹配的文档,数据库将把提供的对象插入到集合中。
1 corresponds to MultiUpdate.对应于MultiUpdate。If set, the database will update all matching objects in the collection. 如果设置,数据库将更新集合中的所有匹配对象。Otherwise only updates first matching document.否则,仅更新第一个匹配文档。
2 -31 are reserved. 保留。Must be set to 0.必须设置为0。
|
selector | BSON document that specifies the query for selection of the document to update.BSON文档,指定用于选择要更新的文档的查询。
|
update | BSON document that specifies the update to be performed. 指定要执行的更新的BSON文档。For information on specifying updates see the Update Operations documentation.有关指定更新的信息,请参阅更新操作文档。
|
There is no response to an OP_UPDATE message.OP_UPDATE消息没有响应。