From cf5a3d2f63acebf628a34d938d17ec7cc6646dac Mon Sep 17 00:00:00 2001 From: wess Date: Thu, 13 Oct 2022 11:47:48 -0400 Subject: [PATCH] Allows document _id to be generated on driver side for return --- composer.lock | 2 +- src/MongoClient.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index 8ab77467f7..1a9ae6a580 100644 --- a/composer.lock +++ b/composer.lock @@ -2257,5 +2257,5 @@ "ext-mongodb": "*" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/src/MongoClient.php b/src/MongoClient.php index 73eb28cc43..263c362b20 100644 --- a/src/MongoClient.php +++ b/src/MongoClient.php @@ -376,6 +376,8 @@ class MongoClient $docObj->{$key} = $value; } + $docObj->_id ??= new BSON\ObjectId(); + $this->query(array_merge([ MongoCommand::INSERT => $collection, 'documents' => [$docObj],