Notification texts go here Contact Us Buy Now!

How to convert List<BsonDocument> to List<Class> in C#

var collection = context.Db.GetCollection<BsonDocument>("DBCollection");

should be:

var collection = context.Db.GetCollection<MyClass>("DBCollection");

That way you can use the Find method to check your FileName and FileNumber using something like:

var objList = await collection.Find(x => x.FileName == "FILENAMEHERE" && x.FileNumber == 1).ToListAsync();
Another Answer:

The list of BsonDocuments can be converted directly to a list of class objects with one line of code.

var objList = JsonConvert.DeserializeObject<List<classname>>(bsonDocList.ToJson());

Make sure you are converting the list of bsondocuments to json and not a string. Hope this helps!

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.