Skip to content

Commit 3de5887

Browse files
Merge branch '6.4' into 7.2
* 6.4: [Routing] Add test to validate that default value is allowed to not match requirement fix handling required options Fix @var phpdoc [Lock] [MongoDB] Enforce readPreference=primary and writeConcern=majority [FrameworkBundle] fix phpdoc in `MicroKernelTrait` Fixed validator translations for Albanian
2 parents 10a1814 + 9b29d12 commit 3de5887

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Store/MongoDbStore.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use MongoDB\Driver\Exception\BulkWriteException;
2121
use MongoDB\Driver\Manager;
2222
use MongoDB\Driver\Query;
23+
use MongoDB\Driver\ReadPreference;
24+
use MongoDB\Driver\WriteConcern;
2325
use MongoDB\Exception\DriverRuntimeException;
2426
use MongoDB\Exception\InvalidArgumentException as MongoInvalidArgumentException;
2527
use MongoDB\Exception\UnsupportedException;
@@ -60,9 +62,9 @@ class MongoDbStore implements PersistingStoreInterface
6062
private array $options;
6163

6264
/**
63-
* @param Collection|Client|Manager|string $mongo An instance of a Collection or Client or URI @see https://docs.mongodb.com/manual/reference/connection-string/
64-
* @param array $options See below
65-
* @param float $initialTtl The expiration delay of locks in seconds
65+
* @param Collection|Database|Client|Manager|string $mongo An instance of a Collection or Client or URI @see https://docs.mongodb.com/manual/reference/connection-string/
66+
* @param array $options See below
67+
* @param float $initialTtl The expiration delay of locks in seconds
6668
*
6769
* @throws InvalidArgumentException If required options are not provided
6870
* @throws InvalidTtlException When the initial ttl is not valid
@@ -88,8 +90,10 @@ class MongoDbStore implements PersistingStoreInterface
8890
* to 0.0 and optionally leverage
8991
* self::createTtlIndex(int $expireAfterSeconds = 0).
9092
*
91-
* writeConcern and readConcern are not specified by MongoDbStore meaning the connection's settings will take effect.
92-
* readPreference is primary for all queries.
93+
* readConcern is not specified by MongoDbStore meaning the connection's settings will take effect.
94+
* writeConcern is majority for all update queries.
95+
* readPreference is primary for all read queries.
96+
*
9397
* @see https://docs.mongodb.com/manual/applications/replication/
9498
*/
9599
public function __construct(
@@ -270,7 +274,11 @@ public function delete(Key $key): void
270274
['limit' => 1]
271275
);
272276

273-
$this->getManager()->executeBulkWrite($this->namespace, $write);
277+
$this->getManager()->executeBulkWrite(
278+
$this->namespace,
279+
$write,
280+
['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
281+
);
274282
}
275283

276284
public function exists(Key $key): bool
@@ -287,7 +295,9 @@ public function exists(Key $key): bool
287295
'limit' => 1,
288296
'projection' => ['_id' => 1],
289297
]
290-
));
298+
), [
299+
'readPreference' => new ReadPreference(ReadPreference::PRIMARY)
300+
]);
291301

292302
return [] !== $cursor->toArray();
293303
}
@@ -329,7 +339,11 @@ private function upsert(Key $key, float $ttl): void
329339
]
330340
);
331341

332-
$this->getManager()->executeBulkWrite($this->namespace, $write);
342+
$this->getManager()->executeBulkWrite(
343+
$this->namespace,
344+
$write,
345+
['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
346+
);
333347
}
334348

335349
private function isDuplicateKeyException(BulkWriteException $e): bool

0 commit comments

Comments
 (0)