@@ -154,8 +154,8 @@ public function getTableListing()
154
154
public function getColumns ($ table )
155
155
{
156
156
$ 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 ]],
159
159
// Convert each document to an array of fields
160
160
['$project ' => ['fields ' => ['$objectToArray ' => '$$ROOT ' ]]],
161
161
// Unwind to get one document per field
@@ -168,11 +168,16 @@ public function getColumns($table)
168
168
'types ' => ['$addToSet ' => ['$type ' => '$fields.v ' ]],
169
169
],
170
170
],
171
+ // Get the most seen field names
172
+ ['$sort ' => ['total ' => -1 ]],
173
+ // Limit to 1,000 fields
174
+ ['$limit ' => 1_000 ],
171
175
// Sort by field name
172
176
['$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 ();
176
181
177
182
$ columns = [];
178
183
foreach ($ stats as $ stat ) {
0 commit comments