Kiran Thakur

Kiran Thakur

  • NA
  • 9
  • 1.1k

Not returning any value in MongoDB using MongoClient C#

Jan 12 2017 7:44 AM
Hi,
 
I have written following code.Code run fine but its not returning any value but my table have more than 500 records. Please do reply ASAP.
  1. static void Main(string[] args)  
  2.         {  
  3.             CallMain(args).Wait();  
  4.             Console.ReadLine();  
  5.         }  
  6.   
  7.         static async Task CallMain(string[] args)  
  8.         {  
  9.             var conString = "myConnectionString";  
  10.             var Client = new MongoClient(conString);  
  11.             var DB = Client.GetDatabase("DatabaseName");  
  12.             var collection = DB.GetCollection<BsonDocument>("TableName");  
  13.             using (var cursor = await collection.Find(new BsonDocument()).ToCursorAsync())  
  14.             {  
  15.                 while (await cursor.MoveNextAsync())  
  16.                 {  
  17.                     foreach (var doc in cursor.Current)  
  18.                     {  
  19.                         Console.WriteLine(doc);  
  20.                     }  
  21.                 }  
  22.             }  

Answers (1)