Can I override default Bson datetime reader to read datetime as utc?
See original GitHub issueThis solution doesn’t work for me.
BsonMapper.Global.RegisterType<DateTime>(
dateTime => new BsonValue(dateTime.ToMillisUnixTimestamp()),
bsonValue => DateTimeExtensions.MillisUnixTimestampToDateTime(bsonValue.AsInt64)
);
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
c# - Storing Utc and Local datetime in Mongo
I have a Mongo C# implementation that stores datetime as UTC. MongoDB.Bson.Serialization.Options.DateTimeSerializationOptions options = MongoDB.
Read more >Datetimes and Timezones - PyMongo 4.4.1 documentation
Reading Time# ... As previously mentioned, by default all datetime.datetime objects returned by PyMongo will be naive but reflect UTC (i.e. the time...
Read more >Mongodb date without timezone and Spring Data - Life in IDE
MongoDB stores by default all dates with time and timezone. ... When you read the date back in the same system (working in...
Read more >Working with dates and times in MongoDB - Prisma
MongoDB will store date and time information using UTC internally, but can easily convert to other timezones at time of retrieval as needed....
Read more >BSON Types
BSON is a binary serialization format used to store documents and make ... The official BSON specification refers to the BSON Date type...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It´s better use Serialize/Deserialize method in this case:
Deserialize Func is
Func<BsonValue, BsonMapper, object>
Serialize Func isFunc<BsonValue, BsonMapper, object>
This will override all DateTime types to convert to Int64 before serialize into Bson.
Hi @Try4W, custom data type are not supported in basic already implemented internal types. But you can write your own mapper getter/setter function (implement
ResolveMember
method).