PHPackages                             legalthings/mongodb-session-handler - 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. legalthings/mongodb-session-handler

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

legalthings/mongodb-session-handler
===================================

A session handler that stores structured data in MongoDB

v2.0.0(7y ago)110.0k↓50%[1 issues](https://github.com/legalthings/mongodb-session-handler/issues)MITPHPPHP &gt;=7.1

Since Oct 8Pushed 7y ago7 watchersCompare

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

READMEChangelog (1)Dependencies (3)Versions (5)Used By (0)

MongoDB session handler
=======================

[](#mongodb-session-handler)

[![Build Status](https://camo.githubusercontent.com/c3c102da68bd09bd03c0aa73cf1c75c5c4104f451ed6d87af9e7df641dfcde88/68747470733a2f2f7472617669732d63692e6f72672f6c6567616c7468696e67732f6d6f6e676f64622d73657373696f6e2d68616e646c65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/legalthings/mongodb-session-handler)[![Code Coverage](https://camo.githubusercontent.com/eeb03d5217445385301895c7af2e7195c107a43c28d5d512bd0b142dc7864079/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c6567616c7468696e67732f6d6f6e676f64622d73657373696f6e2d68616e646c65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/legalthings/mongodb-session-handler/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d8ac23900e99b1ff16264b578c5cd4a29610e3f7390612e55deced6dc3855295/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c6567616c7468696e67732f6d6f6e676f64622d73657373696f6e2d68616e646c65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/legalthings/mongodb-session-handler/?branch=master)

The LegalThings MongoDB session handler stores sessions as structured data in MongoDB. This allows a process to fetch and modify or remove a session based on its data.

Use cases
---------

[](#use-cases)

### Remove user sessions when a password changes

[](#remove-user-sessions-when-a-password-changes)

When you change your password, you want to remove all the other sessions of the user. This is a security measure, the old password may be comprimised and a hacker may already have logged in. Without invalidating his session, he can continue to use the user account even after the password has changed.

### Cache and update user information

[](#cache-and-update-user-information)

For performance reasons you might store the user's information like name, image, team name, etc in the session. When a team changes it's name, you want to find all the sessions of the users within that team and update the information.

Installation
------------

[](#installation)

```
composer require legalthings/mongodb-session-handler

```

**This libary uses the legacy Mongo driver.** If you're running PHP7 or simply are already using the new MongoDB driver, please install [`alcaeus/mongo-php-adapter`](https://packagist.org/packages/alcaeus/mongo-php-adapter).

Usage
-----

[](#usage)

```
$mongo = new MongoClient();
$collection = $mongo->some_db->sessions;
$handler = new MongodbSessionHandler($collection);

session_set_save_handler($handler);
```

To create read-only sessions use `new MongodbSessionHandler($collection, 'r')`

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 90% of commits — single point of failure

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 ~300 days

Total

3

Last Release

2900d ago

Major Versions

v1.0.1 → v2.0.02018-05-31

PHP version history (2 changes)v1.0.0PHP &gt;=5.6.0

v2.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/3379a93d51305df325df9045e1a8b205d195e4e8c01312dff53a000ee79002eb?d=identicon)[jasny](/maintainers/jasny)

![](https://www.gravatar.com/avatar/fb23c3d3e3cfed7ef09c08be522314ed8f4aee9d25c0674ca3b0be7895182f8f?d=identicon)[svenstam](/maintainers/svenstam)

---

Top Contributors

[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (9 commits)")[![moesjarraf](https://avatars.githubusercontent.com/u/5793511?v=4)](https://github.com/moesjarraf "moesjarraf (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/legalthings-mongodb-session-handler/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[doctrine/mongodb-odm

PHP Doctrine MongoDB Object Document Mapper (ODM) provides transparent persistence for PHP objects to MongoDB.

1.1k23.3M301](/packages/doctrine-mongodb-odm)[alcaeus/mongo-php-adapter

Adapter to provide ext-mongo interface on top of mongo-php-library

46412.3M73](/packages/alcaeus-mongo-php-adapter)[moloquent/moloquent

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

120114.6k7](/packages/moloquent-moloquent)[doesntmattr/mongodb-migrations

Managed Database Migrations for MongoDB

23598.7k1](/packages/doesntmattr-mongodb-migrations)[facile-it/mongodb-bundle

Bundle service integration of official \[mongodb/mongo-php-library\](https://github.com/mongodb/mongo-php-library) driver library

38212.1k1](/packages/facile-it-mongodb-bundle)

PHPackages © 2026

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