-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(userSchema): Remove Sparse Unique Indexes from Social Login Fields to Fix CosmosDB Duplicate Key Errors #1814
Conversation
I'm having a bit of trouble testing this. I checked out the branch and created a serverless RU-based CosmosDB for MongoDB on Azure (4.2). When running the api container this happens:
Running it again shows this:
Weirdly enough the same happens on main branch. I don't think I'm doing something wrong here, but I'm also a bit confused about what is happening. When starting the container the CosmosDB is definitely empty. After starting the container some schemas exist: ![]() |
Some progress: I managed to resolve the duplicate collection error by commenting out the keyVMongo object creation here: https://github.com/danny-avila/LibreChat/blob/partial-filter-index/api/cache/keyvMongo.js#L6 It looks like something goes wrong when instantiating that class that breaks migrations or something? I added a redis cache to avoid MongoDB here and both errors from my previous comment disappeared. I was able to create two users successfully.
I'm now trying to figure out the Azure OpenID authentication to test that as well. Edit: Looks like I'm running into this issue: #1521 Don't think I can progress until that weird MongoDB logs collection error is solved :/ |
…pression` instead of `sparse`
8ec3ea9
to
a1c7110
Compare
Linking this comment so that anyone else hoping for a resolution knows
|
please don't close. working on a fix. |
I’ve updated this PR to remove unique: true and sparse: true from the optional social login fields (googleId, facebookId, etc.) and switch them to simple indexes (index: true). This resolves the Cosmos DB “duplicate key” errors caused by multiple null values and ensures compatibility with both Cosmos DB and MongoDB. The email field remains required and unique, preserving overall identity uniqueness.
I’ve updated this PR to remove unique: true and sparse: true from the optional social login fields (googleId, facebookId, etc.) and switch them to simple indexes (index: true). This resolves the Cosmos DB
|
partialFilterExpression
instead of sparse
This is not an acceptable fix..
|
Also, it already works without issue using CosmosDB vCore-based, as opposed to CosmosDB RU-based: https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/choose-model |
okay got it. but... it's all good. we already do a check by using the |
@rubentalstra I already tried it, other incompatibilities surface once you get past the user schema. I'd rather not focus on maintaining a replacement for Mongo, especially when there is a better suited alternative using the same cloud provider. AWS DocumentDB also has no issues. |
okay then that's the answer. not that it won't work thank you @danny-avila. |
Addresses CosmosDB compatibility issue