Previously you have seen how to retrieve the data from the MongoDB that throws out all the details from the Collection. Here we are going to get the specific records from the collection by passing input parameter to the find statement. It filters data in the collection and retrieve backs the selected values, ‘Filters’ acts like ‘Where’ Keyword in SQL server

C# Code:  .Net 4.5 and MongoDB 2.0

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Bson;
using MongoDB.Driver.Core;

namespace RetriveWithFilters
    class Program
        static void Main(string[] args)
        static async Task Method1(string[] args)
            var conString = "mongodb://localhost:27017";
            var Client = new MongoClient(conString);
            var DB = Client.GetDatabase("test");
            var collection = DB.GetCollection<BsonDocument>("store");
            var Filter = new BsonDocument("ProductName", "WH-208");
            var list = await collection.Find(Filter).ToListAsync();
            foreach (var dc in list)

Output will have the records which contains the ProductName as WH-208