I’m trying to save a file in MongoDB:

I want to save UploadTime as type Date, however it is saved as a string. How do I save it as type Date


‘Date’ isn’t a portable type (meaning it’s value can be interpreted differently on different systems), but if that’s not a concern then you can use DateTime.Now.Ticks
Just tried it, no luck
Why not use DateTime? It should save as a proper type. You can specify your own class with types and mark it as a bsondocument
It gets stored as string in MongoDb
Try BsonDateTime.Create(DateTime.Now)
It get stored as String in MongoDB
It might be having trouble converting the date to UTC, which is how Mongo stores all dates. The size of the date may not be matching what Mongo expects for a date field so it’s defaulting to string. It definitely supports C# datetimes, though.
C# devs
null reference exceptions

source