score:0

Accepted answer

The problem was indeed within the method GetCollection<>() once I replaced it with the following code, it worked just fine:

public MongoCollection<T> GetCollection<T>(string name = null)
        {
            string collectionName = name;
            if (collectionName == null)
                collectionName = typeof(T).Name;
            if (Database.CollectionExists(collectionName) == false)
                Database.CreateCollection(collectionName);
            return Database.GetCollection<T>(collectionName);
        }

score:0

You can also change it to something like

var usr = users.AsQueryable().Where(u => u.UserName.Equals(username)).FirstOrDefault();

Related Articles