laravel-mongodb-session
laravel-mongodb-session copied to clipboard
Duplicate key in session when using different browser on same machine
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 have the same problem. I will wait for her decision.
same problem too
Hi All, I had this same problem - take a look at the specific message:
index: id_1 dup key: { id: null }
Note that index is "id_1" and it's complaining that the id is null.
I found that my sessions table had 3 indexes: "_id", "id_1", and "last_activity".
You can see your indexes with:
db.sessions.getIndexes()
I think that "id_1" has been added in error - maybe during the Laravel upgrade to v7 or v8 or when switching session support on from file-based to database.
So the simple job is to remove the "id_1" key:
db.sessions.dropIndex("id_1")
It's now all working for me.