I encountered a problem when trying to paginate data that's coming from mongodb. Here's the code:
$projection = [_id, addresses];
$connection = \DB::connection('mongodb');
$data = $connection->collection('my_collection')
->whereNull('deleted_at');
$data = $this->filter($request, $data);
$data = $data->orderBy('created_at', 'desc')
->paginate(10, $projection);
The problem is when I filter the data using my collection's simple attributes, it is working well, but when I filter using a nested attribute (for example: phone_numbers: [{number: 935345345345}]
, filter via phone_numbers.number), it takes a while. I put indices for all searching attributes.