Legacy Opcodes传统操作码
This page describes legacy opcodes that are no longer supported by MongoDB. These legacy opcodes are:此页面描述了MongoDB不再支持的遗留操作码。这些传统操作码是:
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.从MongoDB 5.1开始,OP_MSG和OP_COMPRESSED是唯一支持向MongoDB服务器发送请求的操作码。
OP_DELETE
The OP_DELETE message is used to remove one or more documents from a collection. The format of the OP_DELETE message is:OP_DELETE消息用于从集合中删除一个或多个文档。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. Reserved for future use.整数值为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。 |
flags | Bit values for the operation: The bit values correspond to the following:操作的位值:位值对应以下内容:
0 corresponds to SingleRemove. If set, the database will remove only the first matching document in the collection. Otherwise all matching documents will be removed.0对应于SingleRemove。如果设置,数据库将仅删除集合中的第一个匹配文档。否则,所有匹配的文档都将被删除。
1-31 are reserved. Must be set to 0.1-31已预订。必须设置为0。
|
selector | BSON document that represent the query used to select the documents to be removed. The selector contains one or more elements, all of which must match for a document to be removed from the collection.BSON文档,表示用于选择要删除的文档的查询。选择器包含一个或多个元素,所有元素必须匹配才能从集合中删除文档。 |
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. The format of the OP_GET_MORE message is:OP_GET_MORE消息用于在数据库中查询集合中的文档。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. Reserved for future use.整数值为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。 |
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. 但是,如果结果多于numberToReaturn,数据库仍将建立游标并将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.0,数据库使用默认返回大小。
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,服务器将该值视为-1(自动关闭游标)。
|
cursorID | Cursor identifier that came in the OP_REPLY. This must be the value that came from the database.OP_REPLY中的游标标识符。这必须是来自数据库的值。 |
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. The format of the OP_INSERT message is:OP_INSERT消息用于将一个或多个文档插入到集合中。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. If set, the database will not stop processing a bulk insert if one fails (for example, due to duplicate IDs). 对应于ContinueOnError。如果设置了,如果批量插入失败(例如,由于重复的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. If multiple errors occur, only the most recent will be reported by getLastError.这使得批量插入的行为类似于一系列单个插入,除了如果任何插入失败,而不仅仅是最后一个插入失败,将设置lastError。如果发生多个错误,getLastError只会报告最近的错误。
1-31 are reserved. Must be set to 0.1-31已预订。必须设置为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. 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消息用于关闭数据库中的活动游标。这对于确保在查询结束时回收数据库资源是必要的。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. Reserved for future use.整数值为0。保留供将来使用。 |
numberOfCursorIDs | The number of cursor IDs that are in the message.消息中的游标ID数。 |
cursorIDs | "Array" of cursor IDs to be closed. If there are more than one, they are written to the socket in sequence, one after another.要关闭的游标ID的“数组”。如果有多个,它们将依次写入套接字。 |
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. The format of the OP_QUERY message is:OP_QUERY消息用于在数据库中查询集合中的文档。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.0已保留。必须设置为0。
1 corresponds to TailableCursor. Tailable means cursor is not closed when the last data is retrieved. Rather, the cursor marks the final object's position. 对应于TailableCursor。可跟踪意味着在检索最后一个数据时游标未关闭。相反,游标标记了最终对象的位置。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. Allow query of replica slave. Normally these return an error except for namespace "local".对应于SlaveOk。允许查询副本从属设备。通常,除了命名空间“local”之外,这些都会返回错误。
3 corresponds to OplogReplay. You need not specify this flag because the optimization automatically happens for eligible queries on the oplog. See oplogReplay for more information.对应于OplogReplay。您不需要指定此标志,因为优化会自动发生在oplog上符合条件的查询上。有关更多信息,请参阅oplogReplay。
4 corresponds to NoCursorTimeout. The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.对应于NoCursorTimeout。服务器通常在非活动期(10分钟)后超时空闲游标,以防止过度使用内存。设置此选项可防止这种情况发生。
5 corresponds to AwaitData. Use with 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.对应于AwaitData。与TailableCursor一起使用。如果游标位于数据末尾,请阻塞一段时间,而不是不返回任何数据。超时后,服务器恢复正常。
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. 限制查询的第一条OP_REPLY消息中的文档数量。但是,如果结果多于numberToReaturn,数据库仍将建立游标并将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(自动关闭游标)。
|
query | BSON document that represents the query. 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.表示查询的BSON文档。查询包含一个或多个元素,所有元素都必须匹配,文档才能包含在结果集中。可能的元素包括$query、$orderby、$hint和$explain。 |
returnFieldsSelector | Optional. 可选。BSON document that limits the fields in the returned documents. 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. 限制返回文档中字段的BSON文档。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_REPLY消息。
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.MongoDB 5.1删除了对OP_QUERY查找操作和OP_QUERY命令的支持。作为例外,OP_QUERY仍然支持在连接握手过程中运行hello和isMaster命令。
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: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
}
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.对应于CursorNotFound。当调用getMore但游标ID在服务器上无效时设置。返回的结果为零。
1 corresponds to QueryFailure. Is set when query failed. Results consist of one document containing an "$err" field describing the failure.对应于QueryFailure。查询失败时设置。结果由一个包含描述失败的“$err”字段的文档组成。
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.对应于ShardConfigStale。司机应该忽略这一点。只有mongos会看到这个集合,在这种情况下,它需要从服务器更新配置。
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.对应于AwaitCapable。当服务器支持AwaitData Query选项时设置。如果没有,客户端应该在Tailable游标的getMore之间睡一会儿。
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. 此OP_REPLY所属的cursorID。如果查询的结果集适合一条OP_REPLY消息,cursorID将为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.此cursorID必须在用于获取更多数据的任何OP_GET_MORE消息中使用,并且当不再需要时,必须由客户端通过OP_KILL_CURSORS消息关闭。 |
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. The format of a OP_UPDATE message is the following:OP_UPDATE消息用于更新集合中的文档。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. Reserved for future use.整数值为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。 |
flags | Bit values for the operation: The bit values correspond to the following:操作的位值:位值对应以下内容:
0 corresponds to Upsert. If set, the database will insert the supplied object into the collection if no matching document is found.对应于Upert。如果设置了,如果找不到匹配的文档,数据库将把提供的对象插入到集合中。
1 corresponds to MultiUpdate.If set, the database will update all matching objects in the collection. Otherwise only updates first matching document.如果设置了MultiUpdateIf,数据库将更新集合中所有匹配的对象。否则,仅更新第一个匹配的文档。
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. For information on specifying updates see the Update Operations documentation.指定要执行的更新的BSON文档。有关指定更新的信息,请参阅更新操作文档。 |
There is no response to an OP_UPDATE message.对OP_UPDATE消息没有响应。