BsonDocument bsonDocument = BsonDocument.Parse("{ date: ISODate('2022-01-01T00:00:00.000Z') }"); BsonReader bsonReader = bsonDocument.CreateReader(); bsonReader.ReadStartDocument(); DateTime date = bsonReader.ReadDateTime("date"); bsonReader.ReadEndDocument(); Console.WriteLine(date.ToString());
BsonDocument bsonDocument = BsonDocument.Parse("{ dates: [ ISODate('2022-01-01T00:00:00.000Z'), ISODate('2022-01-02T00:00:00.000Z') ] }"); BsonReader bsonReader = bsonDocument.CreateReader(); bsonReader.ReadStartDocument(); bsonReader.ReadStartArray(); while (bsonReader.ReadBsonType() != BsonType.EndOfDocument) { DateTime date = bsonReader.ReadDateTime(); Console.WriteLine(date.ToString()); } bsonReader.ReadEndArray(); bsonReader.ReadEndDocument();In this example, a BsonDocument object is created from a string that represents a BSON document with an array of date values. A BsonReader object is then created from the BsonDocument and used to read each date value from the array. The date values are printed to the console.