How to delete a document by _id in MongoDB using VB.Net?

Software Tips and Codes
Using VB.Net to delete document in Mongodb by _id

Searched the internet for how to delete a document in MongoDB using just the_id using VB.Net ?

You would have found only C# code everywhere isn’t it ?

The below code can be used to delete a document in a collection of MongoDB using VB.Net. Internet is flooded with C# examples and not one on using VB.Net, so here it is…

        Imports MongoDB.Bson
        Imports MongoDB.Driver

        Dim connection_database As MongoClient
        Dim database_name As IMongoDatabase
        Dim iDString As String = "60be0eb52630a97b6009ab55"

        connection_database = New MongoClient("mongodb://" & "" & "/")
        database_name = connection_database.GetDatabase("Database_Name")

        Dim collection As IMongoCollection(Of BsonDocument) = database_name.GetCollection(Of BsonDocument)("collection_name")
        Dim filter = Builders(Of BsonDocument).Filter.Eq(Of Object)("_id", ObjectId.Parse(iDString))