jenssegers / laravel-mongodb-session Goto Github PK
View Code? Open in Web Editor NEWA MongoDB session driver for Laravel
A MongoDB session driver for Laravel
This library just able to store the default values. I am also not being able to retrieve the stored value because session id is changed every time I refresh the page. And there is no mechanism by that I add my data to collections.
Please provide with some example how to use this.
I am getting the error message bellow after upgrading to Laravel 4.2. When I looked into the error message it is due to missing implementation of getDefaultDriver method.
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class Jenssegers\Mongodb\Session\SessionManager contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Illuminate\Support\Manager::getDefaultDriver)","file":"G:\Workspace\Luukal Workspace\lk-dev\vendor\jenssegers\mongodb-session\src\Jenssegers\Mongodb\Session\SessionManager.php","line":73}}
"illuminate/session": "~4.0|~5.0"
,however it crashes whenever the driver is selected - some incompatibility with the Symfony session driver.
Error is thrown in Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler
on line 73.
As i am using laravel 5.2, i can store user_id in session table in mysql. How can i store it in laravel session collection.
Thanks
When I use mongodd as the session driver the csrf filter grinds to a halt completely.
I have tried and used the file,cookie and array as the session driver and the CSRF filter worked just fine.
Is there a way to use mongo sessions when the default is mysql?
Hello Sir,
Laravel 6 version in not install can you update package.
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Conclusion: remove laravel/framework v5.0.13
- jenssegers/mongodb-session v1.0.0 requires illuminate/session 4.* -> satisfiable by illuminate/session[v4.0.0, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.1, v4.2.12, v4.2.16, v4.2.17, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
- jenssegers/mongodb-session v1.0.1 requires illuminate/session 4.* -> satisfiable by illuminate/session[v4.0.0, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.1, v4.2.12, v4.2.16, v4.2.17, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
- jenssegers/mongodb-session v1.0.2 requires illuminate/session 4.* -> satisfiable by illuminate/session[v4.0.0, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.1, v4.2.12, v4.2.16, v4.2.17, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
- don't install illuminate/session v4.0.0|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.1|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.10|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.2|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.3|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.4|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.5|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.6|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.7|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.8|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.0.9|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.0|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.1|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.10|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.11|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.12|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.13|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.14|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.15|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.16|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.17|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.18|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.19|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.2|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.20|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.21|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.22|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.23|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.24|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.25|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.26|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.27|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.28|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.29|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.3|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.30|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.4|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.5|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.6|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.7|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.8|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.1.9|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.1|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.12|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.16|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.17|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.2|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.3|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.4|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.5|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.6|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.7|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.8|don't install laravel/framework v5.0.13
- don't install illuminate/session v4.2.9|don't install laravel/framework v5.0.13
- Installation request for laravel/framework == 5.0.13.0 -> satisfiable by laravel/framework[v5.0.13].
- Installation request for jenssegers/mongodb-session ~1.0 -> satisfiable by jenssegers/mongodb-session[v1.0.0, v1.0.1, v1.0.2].
Hi Jens!
I have a problem...
(...)/auth.php
'driver' => 'mongodb',
(...)/session.php
'driver' => 'mongodb',
'connection' => 'mongodb',
OUTPUT Mongo -> db.sessions.find():
{ "_id" : "7iejho7kilhbtu3cquqh3tj6q1", "last_activity" : ISODate("2013-10-27T18:51:21.776Z"), "payload" : BinData(2,"5QAAAF9zZjJfYXR0cmlidXRlc3xhOjI6e3M6NjoiX3Rva2VuIjtzOjQwOiJQZ1JjR0hvOEl2M2tEMFh5ekxYaXNRNU1LT2x2VUN2WjNvNzU2Z0daIjtzOjU6ImZsYXNoIjthOjI6e3M6Mzoib2xkIjthOjA6e31zOjM6Im5ldyI7YTowOnt9fX1fc2YyX2ZsYXNoZXN8YTowOnt9X3NmMl9tZXRhfGE6Mzp7czoxOiJ1IjtpOjEzODI4OTk4ODE7czoxOiJjIjtpOjEzODI4OTczMDk7czoxOiJsIjtzOjQ6IjcyMDAiO30=") }
But recived this error: Driver [mongodb] not supported.
Mongo version: 2.4.7
after composer update
application stopped working with error: Unsupported driver [mongodb]
thrown in: vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php
on line 194
. Changing session driver from mongodb
to i.e. file
resolved this problem.
My Laravel version is current (4.2) and before Laravel MongoDB update to 2.0.0 everything was working without problem.
BTW: I like very much improvements in 2.0.0 :)
Please help and thanks,
Peter
1.4 has not been published to https://packagist.org/packages/jenssegers/mongodb-session
Hey,
I just installed MongoDB session and I can't get it to work. I've done everything according to your instructions and still I get error
Driver [mongodb] not supported
I'm currently using your main MongoDB package and it is working without problem (great job, btw). I figured that this should be a plug'n'play thing, but sadly - it's not.
Thanks for any help :)
It seems that MongoDB doesn't flush stale sessions, and after a few days without rebooting will refuse connections. Does this module implement mongodb's clear_interval option?
Thanks!
Hello, why not follow the database session driver of Laravel 8 ?
Because that way, it ships with some other features like IP address, active connections, loging out from other devices.
It's really a nightmare without this behavior.
I got this response on second browser when trying to open my newly setup laravel app.
E11000 duplicate key error collection: pace.sessions index: id_1 dup key: { id: null }
I'm using latest laravel 8.
laravel-mongodb 3.8
laravel-mongodb-session 1.4
I'm just trying to setup my new project with mongodb support.
This is composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"inertiajs/inertia-laravel": "^0.2.4",
"jenssegers/mongodb": "^3.8",
"jenssegers/mongodb-session": "^1.4",
"laravel/framework": "^8.12",
"laravel/jetstream": "^1.6",
"laravel/sanctum": "^2.6",
"laravel/tinker": "^2.5",
"tightenco/ziggy": "^0.9.4"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
}
}
I just ran into an issue w/ session lifetime.
session.php specifies the value in minutes (I have it set to 1440 which should be 24 hours).
However, in checking the session collection in the DB I find it to be setting expiration 24 minutes from the time last accessed.
Example from my sessions table:
"last_activity" : ISODate("2017-07-19T17:03:41.000Z"),
"expires_at" : ISODate("2017-07-19T17:27:41.000Z"),
Delta is 24 minutes exactly - (should be 24 hours in my case)
Anyone else experiencing this?
UPDATE: Changing the session.php lifetime value to 60, clearing the cache and removing all records from the sessions collection in the DB (and the logging back in) has NO EFFECT(session still timeout in 24 minutes and the DB session collection indicates the same)... This indicates that the lifetime value in the session.php file is not being used, but some 24 minute value elsewhere is being used? Perhaps gc_maxlifetime? Any thoughts on this?
UPDATE: Changing php.ini to reflect: session.gc_maxlifetime = 86400
(and then restarting apache2) seems to have done what I wanted but I'm not sure why this value is being used.
Also, I'm not sure I want the cleanup set to this long a period for PHP... Anyone have any idea why this value is being used by mongodb session driver and not the session.php lifetime ?
Currently, due to deps, this cannot install on Laravel 6, can it be updated to do so?
This isn't necessarily an issue with the code in this library but rather the code in Symfony that this library depends on. SessionManager.php depends on MongoDbSessionHandler.php
from Symfony which is biased to only work with the PHP Mongo Extension having several classes from that extension hardcoded.
I've filed an issue with Symfony here:
symfony/symfony#19183
It would be worthwhile to have an interim solution until the fix for this propagates. I suggest one of the following:
Create/utilize a "shim" that essentially defines all of the Mongo classes, namely, Mongo, MongoClient, MongoId, MongoDate, and MongoBinData that are expected/used by MongoDbSessionHandler.php. This could completely overcome the issue with the exception of MongoDbSessionHandler.php Line 73.
Create a temporary alternate MongoDbSessionHandler.php file that is used if the MongoDB\Client class exists.
I'd suggest (2) since (1) is not a complete solution.
@jenssegers, what are your thoughts? I'm happy to submit a PR for this today.
Hello
I was just wondering if the package implements the automatic TTL function in MongoDB?
I noticed that the package adds the last_activity field to the documents. What defines the TTL? is it the session lifetime configuration in Laravels session.php?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.