I have trouble connecting my mflix cluster which I have created for M220N course

MongoDB Driver Version: 2.12.2
whitelisted IP on the cluster : 0.0.0.0/0 status:Active
DB User: Auth Method: SCRAM Role: atlasAdmin@admin resource:all

I can connect through compass UI.

Code Sample:

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var connString = "mongodb+srv://m220student:m220password@mflix.gcgrf.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
            var client = new MongoClient(connString);
            var db = client.GetDatabase("sample_mflix");
            var collection = db.GetCollection<BsonDocument>("movies");
            var result = collection.Find(new BsonDocument())
               .SortByDescending(m => m["runtime"])
               .Limit(10)
               .ToList();

            foreach (var r in result)
            {
                Console.WriteLine(r.GetValue("title"));
            }

        }
    }

Error:

A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector

I figured this out by read through the other posts.

Replace the connection string created against c# driver version 2.11 or later with connection string created against c# driver version 2.4 or later.

With the above changes programs started working as expected.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.