Legacy Opcodes
This page describes legacy opcodes that are no longer supported by MongoDB. These legacy opcodes are:
Deprecated as of MongoDB 5.0.
Unsupported as of 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. The format of the OP_DELETE message is:
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. }
Field | Description |
---|---|
| Message header. See Standard Message Header. |
| Integer value of 0. Reserved for future use. |
| The full collection name, specifically its namespace. The
namespace is the concatenation of the database name with the
collection name, using a |
| Bit values for the operation: The bit values correspond to the following:
|
| 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. |
There is no response to an OP_DELETE message.
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:
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 }
Field | Description |
---|---|
| Message header. See Standard Message Header. |
| Integer value of 0. Reserved for future use. |
| The full collection name, specifically its namespace. The
namespace is the concatenation of the database name with the
collection name, using a |
| 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 If
|
| Cursor identifier that came in the 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_INSERT
The OP_INSERT message is used to insert one or more documents into a collection. The format of the OP_INSERT message is:
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 }
Field | Description |
---|---|
| Message header. See Standard Message Header. |
| Bit values for the operation: The bit values correspond to the following:
|
| The full collection name, specifically its namespace. The
namespace is the concatenation of the database name with the
collection name, using a |
| 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_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:
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 |
---|---|
| Message header. See Standard Message Header. |
| Integer value of 0. Reserved for future use. |
| The number of cursor IDs that are in the message. |
| "Array" of cursor IDs to be closed. 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
The OP_QUERY message is used to query the database for documents in a collection. The format of the OP_QUERY message is:
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. }
Field | Description | |
---|---|---|
| Message header. See Standard Message Header. | |
| Bit values for the operation: The bit values correspond to the following:
| |
| The full collection name, specifically its namespace. The
namespace is the concatenation of the database name with the
collection name, using a | |
| Sets the number of documents to omit - starting from the first document in the resulting dataset - when returning the result of the query. | |
| 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 If
| |
| 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
| |
| Optional. BSON document that limits the fields in the returned
documents. The
|
The database will respond to an OP_QUERY message with an OP_REPLY message.
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 |
---|---|
| Message header. See Standard Message Header. |
| Bit values for the operation: The bit values correspond to the following:
|
| The |
| Starting position in the cursor. |
| Number of documents in the reply. |
| 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:
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 }
Field | Description |
---|---|
| Message header. See Standard Message Header. |
| Integer value of 0. Reserved for future use. |
| The full collection name, specifically its namespace. The
namespace is the concatenation of the database name with the
collection name, using a |
| Bit values for the operation: The bit values correspond to the following:
|
| BSON document that specifies the query for selection of the document to update. |
| BSON document that specifies the update to be performed. For information on specifying updates see the Update Operations documentation. |
There is no response to an OP_UPDATE message.