diff --git a/src/Auth.php b/src/Auth.php index c2c988f945..ca0aa59bdb 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -218,7 +218,7 @@ class Auth /** * @return string */ - public function getCnonce(): string + public function getCnonce(): ?string { return $this->cnonce; } diff --git a/src/Client.php b/src/Client.php index 29d7ce1245..164a700d94 100644 --- a/src/Client.php +++ b/src/Client.php @@ -202,6 +202,19 @@ class Client (!isset($responseLength)) || ($receivedLength < $responseLength) ); + /* + * The first 21 bytes of the MongoDB wire protocol response consist of: + * - 16 bytes: Standard message header, which includes: + * - messageLength (4 bytes): Total size of the message, including the header. + * - requestID (4 bytes): Identifier for this message. + * - responseTo (4 bytes): The requestID that this message is responding to. + * - opCode (4 bytes): The operation code for the message type (e.g., OP_MSG). + * - 4 bytes: flagBits, which provide additional information about the message. + * - 1 byte: payloadType, indicating the type of the following payload (usually 0 for a BSON document). + * + * These 21 bytes are protocol metadata and precede the actual BSON-encoded document in the response. + */ + $bsonString = substr($res, 21, $responseLength - 21); $result = Document::fromBSON($bsonString)->toPHP(); if (is_array($result)) { @@ -563,7 +576,7 @@ class Client $updateOperation = [ 'q' => $op['filter'], - 'u' => $cleanUpdate, + 'u' => $this->toObject($cleanUpdate), 'upsert' => true, 'multi' => isset($op['multi']) ? $op['multi'] : false, ];