MongoDB E11000 Duplicate "id" Key Error

I've been encountering this issue since I'm using Discord's OAUTH2 with BetterAuth while using MongoDB as an adapter.

The exact error is as shown:
ERROR [Better Auth]: MongoServerError: E11000 duplicate key error collection: credmaid.webusers index: id_1 dup key: { id: null }


I've tried setting generateId to false like:
advanced: {
    database: {
      generateId: false,
    },
    cookiePrefix: "credmaid",
  },


What could be the issue?
Solution
it could be that there are already fields in that webusers table with the id field & it's unique constraint, so even after you updated the mongoose schema it doesn't reflect mongo
Was this page helpful?