using MongoDB.Bson; using MongoDB.Bson.IO; // Assume that 'dataBytes' is a byte array containing BSON-encoded data BsonReader reader = new BsonReader(dataBytes); while (reader.ReadBsonType() != BsonType.EndOfDocument) { // Do something with each BSON element in the data }
using MongoDB.Bson; using MongoDB.Bson.IO; // Assume that 'dataBytes' is a byte array containing BSON-encoded data BsonReader reader = new BsonReader(dataBytes); while (reader.ReadBsonType() != BsonType.EndOfDocument) { if (reader.CurrentBsonType == BsonType.String) { string value = reader.ReadString(); // Do something with the value of the string element } }This example reads each BSON element in the data and checks if it is a string. If it is, the value of the string element is read using the ReadString method. Both of these examples use the MongoDB.Bson.IO package library, which is part of the MongoDB .NET driver.