0

Say I have a business. If I want to turn an object whose class is Business into a BsonDocument, I would do

aBusiness.ToBsonDocument

Great.

What about if I want to turn a BsonDocument into aBusiness class? Is there an easy way?

Public Shared Function ToBsonDocument(Of TNominalType)(ByVal obj As TNominalType) As MongoDB.Bson.BsonDocument Member of MongoDB.Bson.BsonExtensionMethods

user4951
  • 32,206
  • 53
  • 172
  • 282

1 Answers1

2

What you need to do is deserialize your BSonDocument into your class.

Without having a more complete view of your class I can't give a full example, but in general you would need to do something like:

Dim testBusiness As aBusiness = BsonSerializer.Deserialize(Of aBusiness)

You can find the API documentation for the BSonSerializer here

You can also see a similar question for C# here

Community
  • 1
  • 1
Andre de Frere
  • 2,703
  • 16
  • 13