Populate DataGridView with MongoDB Data using Entity in c#

How to populate a DataGridView in Winforms application using C# and data from MongoDB database

Assuming that you already have a model mapped to a collection in MongoDB.

You would like to populate the data in a DataGridView in c#.

We have a model called QuestionBank

 

We will fetch all the records from Mongodb collection using the Filter.Empty

 

 

 

Here is the code

   var documents =  db.QuestionBanks.Find(Builders<QuestionBank>.Filter.Empty).ToListAsync();
   this.dataGridView1.DataSource = documents.Result;

 

 

There is absolutely no need to do any loops to achieve it.