PHPackages                             1ff/laravel-mongodb-session - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. 1ff/laravel-mongodb-session

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

1ff/laravel-mongodb-session
===========================

A mongodb session driver for laravel

v7.0.0(12mo ago)537.0k↓24.5%9MITPHPPHP ^8.2CI passing

Since Aug 30Pushed 9mo ago7 watchersCompare

[ Source](https://github.com/1FF/laravel-mongodb-session)[ Packagist](https://packagist.org/packages/1ff/laravel-mongodb-session)[ RSS](/packages/1ff-laravel-mongodb-session/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (32)Used By (0)

Laravel Mongodb Session driver
==============================

[](#laravel-mongodb-session-driver)

A MongoDB session driver for Laravel

**Laravel
Version****Package
Version****Install using
this command**12.x7.x.xcomposer require 1ff/laravel-mongodb-session:^7.011.x6.x.xcomposer require 1ff/laravel-mongodb-session:^6.010.x5.x.xcomposer require 1ff/laravel-mongodb-session:^5.09.x4.x.xcomposer require 1ff/laravel-mongodb-session:^4.08.x3.x.xcomposer require 1ff/laravel-mongodb-session:^3.07.x2.x.xcomposer require 1ff/laravel-mongodb-session:^2.05.x.x, 6.x1.x.xcomposer require 1ff/laravel-mongodb-session:^1.0Installation
------------

[](#installation)

Install using composer:

```
composer require 1ff/laravel-mongodb-session

```

Change the connection in `config/session.php` to the name of the mongo connection from your `config/database.php` config

```
'connection' =>  'mongodb',

```

Update your .env file and change the `SESSION_DRIVER` to mongodb

```
SESSION_DRIVER=mongodb

```

Advantages
----------

[](#advantages)

- This driver uses the [MongoDB TTL indexes](https://docs.mongodb.com/manual/core/index-ttl/) meaning when a session key expires it will be automatically deleted. So no need for garbage collection implementation.
- This way, the collection's size will remain around the size you expect and won't get falsely filled with unused data.
- The package automatically adds a migration which creates the index. If you change the name of the `session.table` you should rerun the ttl index creation command `php artisan mongodb:session:index`.

Enjoy!
------

[](#enjoy)

Testing
-------

[](#testing)

This package includes a comprehensive test suite to ensure the MongoDB session handler works correctly. The tests cover:

1. Basic session operations (read, write, destroy)
2. Integration with Laravel's session system
3. HTTP session functionality
4. Laravel's testing helpers integration

### Running the Tests

[](#running-the-tests)

To run the tests, follow these steps:

1. Make sure MongoDB is installed and running on your system
2. Install the package dependencies with Composer:

```
composer install
```

3. Run the tests with PHPUnit:

```
vendor/bin/phpunit
```

### Continuous Integration

[](#continuous-integration)

The package includes a GitHub Actions workflow that automatically runs tests on PHP 8.1 with Laravel 10.x against MongoDB 7. The workflow:

1. Sets up a MongoDB service container
2. Installs PHP with MongoDB extension
3. Caches Composer dependencies for faster builds
4. Runs the test suite

This ensures all tests pass before merging new changes.

### Expected Test Results

[](#expected-test-results)

When all tests are passing, you should see output similar to:

```
PHPUnit 10.x.x by Sebastian Bergmann and contributors.

...............                                                   15 / 15 (100%)

Time: 00:00.444, Memory: 32.00 MB

OK (15 tests, 41 assertions)

```

### Testing Environments

[](#testing-environments)

The tests are compatible with:

- PHP 8.1+
- Laravel 10.x
- MongoDB 4.0+

### Test Coverage

[](#test-coverage)

- **Unit Tests**: These test the `MongoDbSessionHandler` methods directly (open, close, read, write, destroy, gc)
- **Feature Tests**: These test the integration with Laravel's session functionality
- **HTTP Tests**: These test session handling in HTTP requests and session persistence
- **Laravel Helper Tests**: These test integration with Laravel's testing helpers like `withSession` and `flushSession`

If you encounter any issues with the tests, please submit an issue on the GitHub repository.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance53

Moderate activity, may be stable

Popularity36

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~74 days

Recently: every ~5 days

Total

29

Last Release

363d ago

Major Versions

2.0.2 → 3.0.22022-07-21

v3.x-dev → 4.0.02022-09-20

v4.x-dev → 5.0.02023-09-01

v5.1.0 → v6.0.02025-05-19

v6.x-dev → v7.0.02025-05-20

PHP version history (2 changes)5.0.0PHP ^8.1

v6.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/35f534b679e79a43f872d066e060600f317f93fd423e6e017cb3ab7a266cbf94?d=identicon)[vcrazy](/maintainers/vcrazy)

---

Top Contributors

[![spont4e](https://avatars.githubusercontent.com/u/10523455?v=4)](https://github.com/spont4e "spont4e (11 commits)")[![t1sh0o](https://avatars.githubusercontent.com/u/3911728?v=4)](https://github.com/t1sh0o "t1sh0o (11 commits)")[![DevquasarX9](https://avatars.githubusercontent.com/u/9060426?v=4)](https://github.com/DevquasarX9 "DevquasarX9 (3 commits)")[![tuseto](https://avatars.githubusercontent.com/u/9108143?v=4)](https://github.com/tuseto "tuseto (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/1ff-laravel-mongodb-session/health.svg)

```
[![Health](https://phpackages.com/badges/1ff-laravel-mongodb-session/health.svg)](https://phpackages.com/packages/1ff-laravel-mongodb-session)
```

###  Alternatives

[jenssegers/mongodb-session

A MongoDB session driver for Laravel 4, 5, 6, 7 and 8

76308.1k3](/packages/jenssegers-mongodb-session)[ytake/laravel-couchbase

Couchbase providers for Laravel

3051.9k](/packages/ytake-laravel-couchbase)[roddy/firestore-eloquent

Firestore Eloquent, an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using Eloquent, each firestore collection has a corresponding \\"Model\\"/\\"Class\\" that is used to interact with that collection. In addition to retrieving records from the firestore collection, Eloquent models/classes allow you to insert, update, and delete records from the collection as well.

161.1k](/packages/roddy-firestore-eloquent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
