Docs Home → Develop Applications → MongoDB Manual
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 |
---|---|
header | Message header. See Standard Message Header. |
ZERO | Integer value of 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 . |
flags | Bit values for the operation: The bit values correspond to the following:
|
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. |
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 |
---|---|
header | Message header. See Standard Message Header. |
ZERO | Integer value of 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 . |
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 If
|
cursorID | 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 |
---|---|
header | Message header. See Standard Message Header. |
flags | Bit values for the operation: The bit values correspond to the following:
|
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 . |
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_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 |
---|---|
header | Message header. See Standard Message Header. |
ZERO | Integer value of 0. Reserved for future use. |
numberOfCursorIDs | The number of cursor IDs that are in the message. |
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. |
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 | |
---|---|---|
header | Message header. See Standard Message Header. | |
flags | Bit values for the operation: The bit values correspond to the following:
| |
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 . | |
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 If
| |
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 . | |
returnFieldsSelector | 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 |
---|---|
header | Message header. See Standard Message Header. |
responseFlags | Bit values for the operation: The bit values correspond to the following:
|
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. 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 |
---|---|
header | Message header. See Standard Message Header. |
ZERO | Integer value of 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 . |
flags | Bit values for the operation: The bit values correspond to the following:
|
selector | BSON document that specifies the query for selection of the
document to update. |
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.