Skip to content

Commit 754c1f6

Browse files
committed
Fix insert operation
1 parent 9699059 commit 754c1f6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Controllers/CollectionController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public function insertOneAction() : Response {
3030
return new JsonResponse(400, ErrorNormalizer::normalize($th, __METHOD__));
3131
}
3232

33+
if ( isset($decodedRequestBody['document']['_id'])
34+
&& preg_match(MongoDBHelper::MDB_OBJECT_ID_REGEX, $decodedRequestBody['document']['_id']) ) {
35+
$decodedRequestBody['document']['_id'] =
36+
new \MongoDB\BSON\ObjectId($decodedRequestBody['document']['_id']);
37+
}
38+
3339
foreach ($decodedRequestBody['document'] as &$insertValue) {
3440
if ( preg_match(MongoDBHelper::ISO_DATE_TIME_REGEX, $insertValue) ) {
3541
$insertValue = new \MongoDB\BSON\UTCDateTime(new \DateTime($insertValue));

0 commit comments

Comments
 (0)