Reputation: 4187
What is the difference between the following ways of connecting to MongoDB server?
MongoServer mongo = MongoServer.Create("mongodb://192.168.11.237:27017")
and
Mongo mongo = new Mongo("mongodb://192.168.11.237:27017");
mongo.TryConnect();
Upvotes: 0
Views: 5027
Reputation: 53675
You are using not official driver. So official driver you can get here. And in official driver you should use:
MongoServer mongo = MongoServer.Create("mongodb://192.168.11.237:27017")
This driver will manage connetions internally, so you no need to care about this yourself.
Upvotes: 3
Reputation: 34204
From the documentation:
Create maintains a table of MongoServer instances it has returned before, so if you call Create again with the same parameters you get the same instance back again.
I assume that you're referring to the TryConnect method from the second MongoDB driver. TryConnect tries to connect to the database and returns a bool, telling you if the attempt was successful or not. This way you don't have to write exception handling yourself.
Upvotes: 1