I'm trying to store relatively huge portion of data into MongoDB, using BulkWrite
for multiple inserts. Data comes from external resource, so I cannot fully control it's content. Amount of data records can reach 15k and even more for single bulk operation. Here is the part of my code:
$bulk = new BulkWrite();
foreach ($data as $id => $item) {
$bulk->update(
['id' => $item['id']],
$item,
['upsert' => true]
);
}
try {
$result = $mongo->getManager()->executeBulkWrite(
'db.collection',
$bulk,
new WriteConcern(WriteConcern::MAJORITY)
);
} catch (\MongoDB\Driver\Exception\UnexpectedValueException $e) {
// we have a problem here
}
From time to time I face exceptions like this:
[MongoDB\Driver\Exception\UnexpectedValueException] Got invalid UTF-8 value serializing '�8'
I don't want to filter all this data, because it will affect performance. Is it possible to get exact record on which this exception occured? As far as I know this data is not available from UnexpectedValueException
object and it's previous exception which is also UnexpectedValueException
.