Skip to content

Commit cc31266

Browse files
committed
Explicit $setOnInsert not necessary
1 parent aabec4d commit cc31266

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Scout/ScoutEngine.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ public function update($models)
126126
'updateOne' => [
127127
['_id' => $model->getScoutKey()],
128128
[
129-
'$setOnInsert' => ['_id' => $model->getScoutKey()],
129+
// The _id field is added automatically when the document is inserted
130+
// Update all other fields
130131
'$set' => $searchableData,
131132
],
132133
['upsert' => true],

tests/Scout/ScoutEngineTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,14 @@ public function testUpdate(): void
485485
[
486486
'updateOne' => [
487487
['_id' => 'key_1'],
488-
['$setOnInsert' => ['_id' => 'key_1'], '$set' => ['id' => 1, 'date' => new UTCDateTime($date)]],
488+
['$set' => ['id' => 1, 'date' => new UTCDateTime($date)]],
489489
['upsert' => true],
490490
],
491491
],
492492
[
493493
'updateOne' => [
494494
['_id' => 'key_2'],
495-
['$setOnInsert' => ['_id' => 'key_2'], '$set' => ['id' => 2]],
495+
['$set' => ['id' => 2]],
496496
['upsert' => true],
497497
],
498498
],
@@ -525,7 +525,7 @@ public function testUpdateWithSoftDelete(): void
525525
[
526526
'updateOne' => [
527527
['_id' => 'key_1'],
528-
['$setOnInsert' => ['_id' => 'key_1'], '$set' => ['id' => 1, '__soft_deleted' => false]],
528+
['$set' => ['id' => 1, '__soft_deleted' => false]],
529529
['upsert' => true],
530530
],
531531
],

0 commit comments

Comments
 (0)