SciSharp / SciSharp/BotSharp

MongoDbContext.cs GetDatabaseName Function Not Working Well

Open
#556 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.1k
Forks
651
Avg merge
15h 2m
Merged PRs (30d)
36

Description

Hi,

I had a problem getting the database name in the function you just wrote. I use the connection string structure provided by MongoDB. I've improved your code below. I updated your structure and authSource to bring the database name from there if there is one. If it fits your structure, you can apply this code in the project.

My connectionString structure "mongodb+srv://server.example.com/?connectTimeoutMS=300000&authSource=aDifferentAuthDB"

private string GetDatabaseName(string mongoDbConnectionString) { int dbNameStartIndex = mongoDbConnectionString.IndexOf("authSource=") + "authSource=".Length; if (dbNameStartIndex < "authSource=".Length) { var databaseName = mongoDbConnectionString.Substring(mongoDbConnectionString.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase) + 1); if (databaseName.Contains("?")) { databaseName = databaseName.Substring(0, databaseName.IndexOf("?", StringComparison.InvariantCultureIgnoreCase)); } return databaseName; } int dbNameEndIndex = mongoDbConnectionString.IndexOf('&', dbNameStartIndex); if (dbNameEndIndex == -1) { dbNameEndIndex = mongoDbConnectionString.Length; } return mongoDbConnectionString.Substring(dbNameStartIndex, dbNameEndIndex - dbNameStartIndex); }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in MongoDbContext.cs at GetDatabaseName and compare its current behavior with the MongoDB connection string example in the issue. Check extraction when authSource is present and when the database name follows the slash, including query parameters; done means both forms return the intended database name.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, mongodb
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.