/// <summary>
 /// Tests the MongoDB connection.
 /// </summary>
 /// <param name="connectionString">MongoDB connection string to use to connect.</param>
 public void TestConnection(string connectionString)
 {
     if (String.IsNullOrEmpty(connectionString))
         throw Errors.ConnectionStringMissing();
     
     var server = new MongoClient(connectionString).GetServer();
     server.Connect();
     server.Disconnect();
 }
        public void Initialize()
        {
            var url = new MongoUrl(configuration.ConnectionString);

            MongoRetryPolicy.ExecuteAction(() =>
            {
                var server = new MongoClient(url).GetServer();
                server.Connect();

                var collection = server.GetDatabase(url.DatabaseName).GetCollection(configuration.Collection);
                var mongoCursor = String.IsNullOrEmpty(configuration.Query) 
                    ? collection.FindAll()
                    : collection.Find(new QueryDocument(BsonSerializer.Deserialize<BsonDocument>(configuration.Query)));

                documentsCursor = mongoCursor.SetFields(ParseProjection(configuration.Projection)).GetEnumerator();
            });
        }
Exemple #3
0
 public static MongoServer Connect()
 {
     MongoServer server = new MongoClient(DatabaseSettings.Instance.ConnectionString).GetServer();
     server.Connect();
     return server;
 }