question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MongoDB connection string with options

See original GitHub issue

My mongodb connection string looks like: “mongodb://user:password@localhost:27017/Identity?ssl=true&authSource=admin” when I break it to MongoDbSettings as

"MongoDbSettings": { "ConnectionString": "mongodb://user:password@localhost:27017/", "DatabaseName": "Identity?ssl=true&authSource=admin" }

I can’t connect to the database, am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alexandre-spiesercommented, Dec 4, 2018

Currently, there is no interface allowing you to pass an SSL cert, but you can easily create a custom class inheriting from MongoDbContext with your desired parameters and pass it to the extension:

        public static IdentityBuilder AddMongoDbStores<TUser, TRole, TKey>(this IdentityBuilder builder, IMongoDbContext mongoDbContext)
                    where TUser : MongoIdentityUser<TKey>, new()
                    where TRole : MongoIdentityRole<TKey>, new()
                    where TKey : IEquatable<TKey>

To create a MongoDbContext, you can look in the MongoDbGenericRepository documentation, which is a dependency from the AspNetCore.Identity.MongoDbCore nuget package.

var client = new MongoClient(connectionString);
var mongoDbDatabase = Client.GetDatabase(databaseName);

There is a MongoDbContext constructor that takes a MongoDbDatabase.

        /// <summary>
        /// The constructor of the MongoDbContext, it needs an object implementing <see cref="IMongoDatabase"/>.
        /// </summary>
        /// <param name="mongoDatabase">An object implementing IMongoDatabase</param>
        public MongoDbContext(IMongoDatabase mongoDatabase)
        {
            // Avoid legacy UUID representation: use Binary 0x04 subtype.
            InitializeGuidRepresentation();
            Database = mongoDatabase;
            Client = Database.Client;
        }

You can use a custom class inheriting from MongoDbContext that implements all the functionality you need, including a constructor or methods that take a certificate. The current implementation can be seen here.

0reactions
renatogbpcommented, Dec 3, 2018

Thanks! Where do I set the certificate path and password for the SSL hand shake?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection String URI Format
A query string that specifies connection specific options as <name>=<value> pairs. See Connection String Options for a full description of these options.
Read more >
Connection String URI Format
Standard Connection String Format¶. This section describes the standard format of the MongoDB connection URI used to connect to a MongoDB database server....
Read more >
MongoDB Connection String | Introduction
There are three types of MongoDB connection string that you'll encounter: A MongoDB Atlas connection string, a connection string for an instance running...
Read more >
Connection String in MongoDB (with examples)
The standard format for connecting strings. There are three basic types of MongoDB deployments: standalone, replica set, and sharded cluster, ...
Read more >
Get Connection String — Start with Guides
Navigate to the Database Deployments page for your project. · Click the Connect button. · Copy the connection string.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found