[EF-89] Cannot use connection strings with multiple mongos instances Created: 20/Dec/23  Updated: 03/Jan/24  Resolved: 03/Jan/24

Status: Closed
Project: Entity Framework
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Scott Newton Assignee: Damien Guard
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

{{I'm using a sharded database, with multiple mongos instances.  I would like to list them all in my connection string, such as "mongodb://server1:27107,server2:27017,server3:27017".  }}

This connection string works just fine with several other clients, but the EF Framework driver gives me a parsing error.



 Comments   
Comment by Damien Guard [ 03/Jan/24 ]

Hi Scott.

Fix is now checked in and will go out with the next preview release which will be in a while. Hopefully the workaround will see you through in the mean time.

Damien

Comment by Damien Guard [ 03/Jan/24 ]

My response (over email) was:

I'll ask our PM to figure out what's going on with the permissions.
 
I was able to confirm that the string overload for UseMongoDb does indeed fail with that multiple syntax. It is expecting a URI and the format we use for specifying multiple servers is not actually a URI and so when we try to parse it in the EF provider to sanitize any passwords (for logging) the .NET built-in URI parser fails.
 
As a workaround for now you can create and pass in a MongoClient object demonstrated in this ticket/on the README which doesn't go through that code path and works fine with multiple servers.
 
Thanks!

Comment by Damien Guard [ 03/Jan/24 ]

Customer was unable to respond here (hopefully now fixed) so quoting their response here for reference:

 

I apologize in advance for messaging you directly, but either I'm incapable of finding the reply button on the website, or I don't have permission to reply to the issue on Jira.

Anyways, this is a follow-up to this issue: EF-89 Cannot use connection strings with multiple mongos instances - MongoDB Jira

I've created a basic demo application which recreates the issue for you: EDCScott/MongoConnectionStringDemo (github.com)

The demo repo contains a readme with instructions on how to recreate my test environment as well, in case that is a factor in reproducing the issue.

Comment by Damien Guard [ 02/Jan/24 ]

Hi Scott.

I tried to reproduce this using the following and I'm not getting a parsing error.

var client = new MongoClient("mongodb://server1:27107,server2:27017,server3:27017");
var newOptions = new DbContextOptionsBuilder()
    .UseMongoDB(client, "myDb")
    .Options;

Can you provide a specific code sample/reproduction showing how you get the error?

Thanks,

Damien

 

Generated at Thu Feb 08 08:26:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.