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.
welcome to Stack Overflow. Maybe you need to convert your near origin parameter specifically with BsonDateTime prior to conversion of the entire object, like so:
new BsonDateTime(origin)
In the future it is easier for us to assist if you paste the code rather than the picture whenever possible.