I'm using MongoDB Atlas and creating search pipeline using C# dictionary object then serializing it to json and then parsing the json string to BsonDocument.
In $search stage I'm using near object in compound should with origin date for sorting.
As you can see I'm creating an object for near in which my origin is DateTime.UtcNow
Here is my function which converts Dictionary objects to BsonDocument
This is my BsonDocument after converting Dictionary objects to Json and then converting to Bson
Here I'm using it in agreegation pipeline
The main problem is mongodb is not accepting C# DateTime as a date in origin.
Please guide me how can i give proper MongoDb date from my C# code.