danny-avila / LibreChat

Enhanced ChatGPT Clone: Features Anthropic, AWS, OpenAI, Assistants API, Azure, Groq, o1, GPT-4o, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, langchain, DALL-E-3, ChatGPT Plugins, OpenAI Functions, Secure Multi-User System, Presets, completely open-source for self-hosting. Actively in public development.
https://librechat.ai/
MIT License
17.57k stars 2.91k forks source link

[Bug]: Using Cosmos DB: E11000 duplicate key error when new user attempts login or registration #1747

Closed robsaccone closed 7 months ago

robsaccone commented 7 months ago

What happened?

Using Azure Cosmos DB as backend, which (poorly) emulates Mongo DB, and as a result have encountered a number of issues. This one is due to unique indexes being created in the users collection for each of the "social login" options (facebookId, etc.).

Apparently Cosmos DB doesn't support sparse unique indexes, i.e. treats multiple NULL values as duplicates. I am using OpenID only, so manually deleting the other indexes in the collection solved the issue.

Not looking for a fix here per se, as I'm beginning to realize that Cosmos DB should be consider a semi-supported choice given it's API emulation. Adding detail for others who might try the same, and perhaps for those who might have ideas to better support both Cosmos and Mongo.

Steps to Reproduce

  1. Deploy using Azure Cosmos DB as database vs. Mongo native.
  2. Have more than one user attempt login or registration
  3. Get duplicate key error.

What browsers are you seeing the problem on?

No response

Relevant log output

E11000 duplicate key error collection: test.users. Failed _id or unique index constraint.

Screenshots

image

Code of Conduct

danny-avila commented 7 months ago

Yeah this is a known issue for me. I might be able to remove the sparse field as I’m not sure it’s needed. Still need to investigate the effects of removing it.

I’ve heard DocumentDB is a good enterprise level, cloud alternative (AWS)

robsaccone commented 7 months ago

Thanks Danny. Thinking of dropping Cosmos and either containerizing Mongo as prescribed or using Atlas. Most of my clients are big Azure shops, hence my first attempt at an Azure-first approach. Painful so far but it's working. About to deploy the assistants branch to Azure...