Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

Why I got duplicate key error collection: sessions index error with jenssegers/mongodb?

I started new laravel 9 (with jet and inertia, without team) app with "jenssegers/mongodb": "^3.9" installed. I changed connection to mongo MngProducts database and run migrations.

But running homepage with controller defined I got error on second request :

E11000 duplicate key error collection: MngProducts.sessions index: id_1 dup key: { id: "loBh99XTp9cm3Qj17YqKhVFTuxM8bvpd14wczWQa" }

In Compass I see 1 row in sessions : https://prnt.sc/irFNeSAU-zN4

I migrated all default 4 laravel tables(without any data in them) and why I have this error and how that can be fixed?

Thanks!

0 likes
2 replies
mstdmstd's avatar

Setting in .env file :

SESSION_DRIVER=file

fixed this issue.

laxit's avatar

had same error, it was adding that extra id_1 index. that index is coming from the OG session table.

in my case I wanted to create Session Model, like an event session. it also had the same name as session table of OG Laravel session table and somehow indexes we're replicated here as well.

all I did was refactored my Session to VenueSession and its working great!

my setup:

"laravel/framework": "^12.0",
"mongodb/laravel-mongodb": "^5.3",

Please or to participate in this conversation.