File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -154,16 +154,24 @@ 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 ]],
159
+ // Convert each document to an array of fields
157
160
['$project ' => ['fields ' => ['$objectToArray ' => '$$ROOT ' ]]],
161
+ // Unwind to get one document per field
158
162
['$unwind ' => '$fields ' ],
163
+ // Group by field name, count the number of occurrences and get the types
159
164
[
160
165
'$group ' => [
161
166
'_id ' => '$fields.k ' ,
162
167
'total ' => ['$sum ' => 1 ],
163
168
'types ' => ['$addToSet ' => ['$type ' => '$fields.v ' ]],
164
169
],
165
170
],
171
+ // Sort by field name
166
172
['$sort ' => ['_id ' => 1 ]],
173
+ // Limit to 1,000 fields
174
+ ['$limit ' => 1000 ],
167
175
], ['typeMap ' => ['array ' => 'array ' ]])->toArray ();
168
176
169
177
$ columns = [];
You can’t perform that action at this time.
0 commit comments