Not Exists in MongoDB with C# 2.2.4 driver

NotExists will be used when you are going to retrieve the data which doesn’t have a specific node in the document. It can be used along with find Query while retrieving the data. Below Example is executed with MongoC# 2.2.4 driver.

Example:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Bson;
using MongoDB.Shared;
using MongoDB.Driver.Builders;


namespace MCNotexists
{
    public class Program
    {
        static void Main(string[] args)
        {
            string conString = "mongodb://ampleServiceQA:ampleServiceQAPassword@10.10.11.11:27017/ampleServiceQA";
            var Client = new MongoClient(conString);
            var DB = Client.GetDatabase("ampleServiceQA");
            var query = Query<ample>.NotExists(u => u.style.number);
            var builder = Builders<BsonDocument>.Filter;
            var collection = DB.GetCollection<BsonDocument>("amplecollection");
            var filter = builder.Exists("style", false);
            var RetrievedData = collection.Find(filter).ToList();
            foreach (var doc in RetrievedData)
            {
                Console.WriteLine(doc);
            }
            Console.ReadLine();
        }

        public class ample
        {
            public Style style { get; set; }
        }
        public class Style
        {
            public string description { get; set; }
            public string number { get; set; }
        }
    }
}