PHP version: 7.1.1
Laravel version: 5.6
Package version: 3.0
MongoDB version: 3.0
Hi,
My application uses jenssegers/laravel-mongodb package.
I'm having problems with the Queued Process.
Documentation Page
My Export Code:
class ModelExport implements FromQuery, WithHeadings, WithMapping, ShouldQueue
{
use Exportable;
public function query()
{
return Model::query();
}
public function headings(): array
{
return [
'Code',
'Name',
];
}
public function map($item): array
{
return [
$item->code,
$item->name,
];
}
}
My Job Code:
(new QuotationsMCExport())->store($filename);
Exception:
Exception: Serialization of 'MongoDB\Driver\Manager' is not allowed in .../vendor/maatwebsite/excel/src/Jobs/ExtendedQueueable.php:21
Thanks a lot!
Thanks for submitting the ticket. Unfortunately the information you provided is incomplete. We need to know which version you use and how to reproduce it. Please include code examples. Before we can pick it up, please check (https://github.com/Maatwebsite/Laravel-Excel/blob/3.0/.github/ISSUE_TEMPLATE.md) and add the missing information. To make processing of this ticket a lot easier, please make sure to check (https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/contributing) and double-check if you have filled in the issue template correctly. This will allow us to pick up your ticket more efficiently. Issues that follow the guidelines correctly will get priority over other issues.
We only accepts Eloquent queries currently. MongoDB might work, but we can't guarantee it. It's trying to serialize something that's in your Model that we don't have control over.
Besides that I don't know whether MongoDB would work, you should pass something serializable to your Export class, e.g. instructions on how to create the query builder object.
For illustrative purpose:
// An array containing instructions on how to build the query...
$instructions = [
'where' => [ ['size', '>', 2], ... ]
];
// Member function of the Export class that takes these instructions
protected function makeQuery($instructions){
$q = SomeModel::query();
foreach($instructions['where'] as $where)
$q->where($where[0], $where[1], $where[2]);
return $q;
}
@tomlankhorst thanks for your comment. We already serialize the Eloquent query when queuing it. We can do the same for Mongo, but as I'm not using it, it's not really a priority for me to fix this now. If someone wants to give it a shot, happy to review the PR.
@patrickbrouwers
Thought it wouldn't be possible as both of these lines throw an exception, at least with a MySQL backend:
// Exception with message 'Serialization of 'Closure' is not allowed'
serialize(Product::query());
// Exception with message 'Serialization of 'Closure' is not allowed'
serialize(Product::getQuery());
We use a trick to do so, we don't serialize the query as-is
Hey guys, I'm facing the same problem "Serialization of 'MongoDB\Driver\Manager' is not allowed".
I read this issue and don't understand or found a solution for this, anyone can give me a light?
@tomlankhorst How to apply this class to my export class?
Do not have Mongo driver in your job constructor. Find another way to call it.
Most helpful comment
Hey guys, I'm facing the same problem "Serialization of 'MongoDB\Driver\Manager' is not allowed".
I read this issue and don't understand or found a solution for this, anyone can give me a light?
@tomlankhorst How to apply this class to my export class?