Skip to content

Commit cda02a9

Browse files
committed
Reduce $sample size to fit with Atlas M0
1 parent cf3eb71 commit cda02a9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Schema/Builder.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ public function getTableListing()
154154
public function getColumns($table)
155155
{
156156
$stats = $this->connection->getMongoDB()->selectCollection($table)->aggregate([
157-
// Sample 10,000 documents to get a representative sample of the collection
158-
['$sample' => ['size' => 10_000]],
157+
// Sample 1,000 documents to get a representative sample of the collection
158+
['$sample' => ['size' => 1_000]],
159159
// Convert each document to an array of fields
160160
['$project' => ['fields' => ['$objectToArray' => '$$ROOT']]],
161161
// Unwind to get one document per field
@@ -168,11 +168,16 @@ public function getColumns($table)
168168
'types' => ['$addToSet' => ['$type' => '$fields.v']],
169169
],
170170
],
171+
// Get the most seen field names
172+
['$sort' => ['total' => -1]],
173+
// Limit to 1,000 fields
174+
['$limit' => 1_000],
171175
// Sort by field name
172176
['$sort' => ['_id' => 1]],
173-
// Limit to 1,000 fields
174-
['$limit' => 1000],
175-
], ['typeMap' => ['array' => 'array']])->toArray();
177+
], [
178+
'typeMap' => ['array' => 'array'],
179+
'allowDiskUse' => true,
180+
])->toArray();
176181

177182
$columns = [];
178183
foreach ($stats as $stat) {

0 commit comments

Comments
 (0)