1

I have a MongoDB connection string with the DB included. I am currently initializing the collection this way:

var mongoUrl = new MongoUrl(_connectionString);
var mongoClient = new MongoClient(mongoUrl);
var mongoServer = mongoClient.GetServer();
var mongoDatabase = mongoServer.GetDatabase(mongoUrl.DatabaseName);
_defaultCollection = mongoDatabase.GetCollection<Comment>("comments");

This works fine but just seems longer than it should be. Am I missing a less chatty way of doing the same thing?

Thanks Matthew

1 Answer 1

1

Unfortunately you're not missing out on a thing - it's indeed a cumbersome way of achieving a common task.

I would encourage you to have a look at the excellent open source MongoRepository project which makes such simple tasks a breeze.

Sign up to request clarification or add additional context in comments.

1 Comment

OK great. It is not a big deal as most of it gets written once in a base class and then pretty much ignored...it just seemed like I must be missing something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.