Library: MongoDB
Package: MongoDB
Header: Poco/MongoDB/OpMsgMessage.h
Description
This class represents a request/response (OP_MSG) to send requests and receive responses to/from MongoDB.
THREAD SAFETY: This class is NOT thread-safe. OpMsgMessage instances must not be accessed concurrently from multiple threads without external synchronization. Each thread should use its own message instances.
Inheritance
Direct Base Classes: Message
All Base Classes: Message
Member Summary
Member Functions: acknowledgedRequest, body, clear, collectionName, commandName, databaseName, documents, flags, read, responseOk, send, setAcknowledgedRequest, setCommandName
Inherited Functions: header, messageLength
Enumerations
Flags
MSG_CHECKSUM_PRESENT = (1 << 0)
MSG_MORE_TO_COME = (1 << 1)
Sender will send another message and is not prepared for overlapping messages
MSG_EXHAUST_ALLOWED = (1 << 16)
Client is prepared for multiple replies (using the moreToCome bit) to this request
Constructors
OpMsgMessage
OpMsgMessage();
Creates an OpMsgMessage for response.
OpMsgMessage
OpMsgMessage(
const std::string & databaseName,
const std::string & collectionName,
UInt32 flags = MSG_FLAGS_DEFAULT
);
Creates an OpMsgMessage for requests.
Destructor
~OpMsgMessage
virtual ~OpMsgMessage();
Member Functions
acknowledgedRequest
[[nodiscard]]
bool acknowledgedRequest() const;
body
Document & body();
Access to body document. Additional query arguments shall be added after setting the command name.
body
[[nodiscard]]
const Document & body() const;
clear
void clear();
Clears the message.
collectionName
[[nodiscard]]
const std::string & collectionName() const;
commandName
[[nodiscard]]
const std::string & commandName() const;
Current command name.
databaseName
[[nodiscard]]
const std::string & databaseName() const;
documents
Document::Vector & documents();
Documents prepared for request or retrieved in response.
documents
[[nodiscard]]
const Document::Vector & documents() const;
Documents prepared for request or retrieved in response.
flags
[[nodiscard]]
UInt32 flags() const;
read
void read(
std::istream & istr
);
Reads the response from the stream. The message is cleared first, so that a reused message never holds parts of two responses. The message must carry an OP_MSG opcode and exactly one body section.
Only bounds are checked (see Document::read); documents may exceed BSON_MAX_DOCUMENT_SIZE, as the server returns larger ones. Throws DataFormatException if a check fails, NotImplementedException for an unsupported element type, and IOException if the stream ends early.
responseOk
[[nodiscard]]
bool responseOk() const;
Reads "ok" status from the response message.
send
void send(
std::ostream & ostr
);
Writes the request to stream.
Throws InvalidArgumentException, before anything is written, if the message exceeds MAX_MESSAGE_SIZE_BYTES, a document of the document sequence exceeds BSON_MAX_DOCUMENT_SIZE + 16 KiB, nesting is too deep, a name contains a null character or MSG_CHECKSUM_PRESENT is set, which is not supported, and RangeException for a BSONTimestamp outside 1970-2106. Other limits are left to the server.
setAcknowledgedRequest
void setAcknowledgedRequest(
bool ack
);
Set false to create request that does not return response. It has effect only for commands that write or delete documents. Default is true (request returns acknowledge response).
setCommandName
void setCommandName(
const std::string & command
);
Sets the command name and clears the command document
Variables
CMD_AGGREGATE
static const std::string CMD_AGGREGATE;
CMD_BUILD_INFO
static const std::string CMD_BUILD_INFO;
CMD_COLL_STATS
static const std::string CMD_COLL_STATS;
CMD_COUNT
static const std::string CMD_COUNT;
Legacy command; outside Stable API v1 since MongoDB 5.0. Prefer aggregation $count (see Database::count).
CMD_CREATE
static const std::string CMD_CREATE;
CMD_CREATE_INDEXES
static const std::string CMD_CREATE_INDEXES;
CMD_DB_STATS
static const std::string CMD_DB_STATS;
CMD_DELETE
static const std::string CMD_DELETE;
CMD_DISTINCT
static const std::string CMD_DISTINCT;
CMD_DROP
static const std::string CMD_DROP;
CMD_DROP_DATABASE
static const std::string CMD_DROP_DATABASE;
CMD_FIND
static const std::string CMD_FIND;
CMD_FIND_AND_MODIFY
static const std::string CMD_FIND_AND_MODIFY;
CMD_HELLO
static const std::string CMD_HELLO;
CMD_HOST_INFO
static const std::string CMD_HOST_INFO;
CMD_INSERT
static const std::string CMD_INSERT;
CMD_KILL_CURSORS
static const std::string CMD_KILL_CURSORS;
CMD_LIST_DATABASES
static const std::string CMD_LIST_DATABASES;
CMD_LIST_INDEXES
static const std::string CMD_LIST_INDEXES;
CMD_MAP_REDUCE
static const std::string CMD_MAP_REDUCE;
CMD_PING
static const std::string CMD_PING;
CMD_REPL_SET_GET_CONFIG
static const std::string CMD_REPL_SET_GET_CONFIG;
CMD_REPL_SET_GET_STATUS
static const std::string CMD_REPL_SET_GET_STATUS;
CMD_UPDATE
static const std::string CMD_UPDATE;