Docs Menu
Docs Home
/ / /
Laravel MongoDB

Queues

To use MongoDB as your database for Laravel Queue, change the driver in your application's config/queue.php file:

'connections' => [
'database' => [
'driver' => 'mongodb',
// You can also specify your jobs-specific database
// in the config/database.php file
'connection' => 'mongodb',
'collection' => 'jobs',
'queue' => 'default',
// Optional setting
// 'retry_after' => 60,
],
],

The following table describes properties that you can specify to configure the behavior of the queue:

Setting
Description
driver
Required Queue driver to use. The value of this property must be mongodb.
connection
Database connection used to store jobs. It must be a mongodb connection. The driver uses the default connection if a connection is not specified.
collection
Required Name of the MongoDB collection to store jobs to process.
queue
Required Name of the queue.
retry_after
Specifies how many seconds the queue connection should wait before retrying a job that is being processed. The value is 60 by default.

To use MongoDB to handle failed jobs, create a failed entry in your application's config/queue.php file and specify the database and collection:

'failed' => [
'driver' => 'mongodb',
'database' => 'mongodb',
'collection' => 'failed_jobs',
],

The following table describes properties that you can specify to configure how to handle failed jobs:

Setting
Description
driver
Required Queue driver to use. The value of this property must be mongodb.
connection
Database connection used to store jobs. It must be a mongodb connection. The driver uses the default connection if a connection is not specified.
collection
Name of the MongoDB collection to store failed jobs. The value is failed_jobs by default.

Then, add the service provider in your application's config/app.php file:

MongoDB\Laravel\MongoDBQueueServiceProvider::class,

Job batching is a Laravel feature that enables you to execute a batch of jobs and related actions before, after, and during the execution of the jobs from the queue. To learn more about this feature, see Job Batching in the Laravel documentation.

In MongoDB, you don't have to create a designated collection before using job batching. The job_batches collection is created automatically to store metadata about your job batches, such as their completion percentage.

To enable job batching, create the batching entry in your application's config/queue.php file:

'batching' => [
'driver' => 'mongodb',
'database' => 'mongodb',
'collection' => 'job_batches',
],

The following table describes properties that you can specify to configure job batching:

Setting
Description
driver
Required Queue driver to use. The value of this property must be mongodb.
connection
Database connection used to store jobs. It must be a mongodb connection. The driver uses the default connection if a connection is not specified.
collection
Name of the MongoDB collection to store job batches. The value is job_batches by default.

Then, add the service provider in your application's config/app.php file:

MongoDB\Laravel\MongoDBBusServiceProvider::class,

Back

Cache and Locks