REF: https://groups.google.com/forum/#!topic/mongodb-user/yfbzkozHS64
Hi,
Perhaps I'm not use this method properly but I think I am. Here is my code:
IMongoCollection<TType> c = _database2.GetCollection<TType>("MyDocuments"); var f1 = new FilterDefinitionBuilder<TType>(); var fluent = c.Find(f1.Text(queryFilter.SearchTerm)); var result = fluent.CountAsync();
When CountAsync executes (I normally would attach a .Result, but I wanted to isolate the issue here), it throws the following exception:
Object reference not set to an instance of an object.
at MongoDB.Driver.FindFluent`2.CountAsync(CancellationToken cancellationToken)
at ProfileUnity.Mongo.Db.MongoDatabaseManager.<>c__DisplayClass9`1.<GetAll>b__8() in d:\work\proudotnet\src\ProfileUnity.Mongo.Db\MongoDatabaseManager.cs:line 192
I should mention that when I comment out the CountAsync() and replace it with:
var result = fluent.ToListAsync().Result
My correct results are returned. Any advice?
Thanks