Skip to content

Commit 78e2453

Browse files
committed
fix: use correct collections for upload to mongodb
1 parent 24c4dab commit 78e2453

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Flow/Mongo/MongoFile.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use MongoDB\BSON\Binary;
1010
use MongoDB\BSON\ObjectId;
1111
use MongoDB\BSON\UTCDateTime;
12-
use MongoDB\Operation\FindOneAndUpdate;
12+
use MongoDB\Operation\FindOneAndReplace;
1313

1414

1515
/**
@@ -48,8 +48,8 @@ protected function getGridFsFile()
4848
$gridFsFileQuery = $this->getGridFsFileQuery();
4949
$changed = $gridFsFileQuery;
5050
$changed['flowUpdated'] = new UTCDateTime();
51-
$this->uploadGridFsFile = $this->config->getGridFs()->getFilesCollection()->findOneAndUpdate($gridFsFileQuery, $changed,
52-
['upsert' => true, 'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER]);
51+
$this->uploadGridFsFile = $this->config->getGridFs()->getFilesCollection()->findOneAndReplace($gridFsFileQuery, $changed,
52+
['upsert' => true, 'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER]);
5353
}
5454

5555
return $this->uploadGridFsFile;
@@ -61,7 +61,7 @@ protected function getGridFsFile()
6161
*/
6262
public function chunkExists($index)
6363
{
64-
return $this->config->getGridFs()->getFilesCollection()->findOne([
64+
return $this->config->getGridFs()->getChunksCollection()->findOne([
6565
'files_id' => $this->getGridFsFile()['_id'],
6666
'n' => (intval($index) - 1)
6767
]) !== null;
@@ -97,7 +97,7 @@ public function saveChunk($additionalUpdateOptions = [])
9797
throw new Exception("Invalid upload! (size: $actualChunkSize)");
9898
}
9999
$chunk['data'] = new Binary($data, Binary::TYPE_GENERIC);
100-
$this->config->getGridFs()->getFilesCollection()->replaceOne($chunkQuery, $chunk, array_merge(['upsert' => true], $additionalUpdateOptions));
100+
$this->config->getGridFs()->getChunksCollection()->replaceOne($chunkQuery, $chunk, array_merge(['upsert' => true], $additionalUpdateOptions));
101101
unlink($file['tmp_name']);
102102

103103
$this->ensureIndices();
@@ -106,7 +106,7 @@ public function saveChunk($additionalUpdateOptions = [])
106106
} catch (Exception $e) {
107107
// try to remove a possibly (partly) stored chunk:
108108
if (isset($chunkQuery)) {
109-
$this->config->getGridFs()->getFilesCollection()->deleteMany($chunkQuery);
109+
$this->config->getGridFs()->getChunksCollection()->deleteMany($chunkQuery);
110110
}
111111
throw $e;
112112
}
@@ -118,7 +118,7 @@ public function saveChunk($additionalUpdateOptions = [])
118118
public function validateFile()
119119
{
120120
$totalChunks = intval($this->request->getTotalChunks());
121-
$storedChunks = $this->config->getGridFs()->getFilesCollection()
121+
$storedChunks = $this->config->getGridFs()->getChunksCollection()
122122
->countDocuments(['files_id' => $this->getGridFsFile()['_id']]);
123123
return $totalChunks === $storedChunks;
124124
}

0 commit comments

Comments
 (0)