using System; using MongoDB.Driver; using MongoDB.Bson; class Program { static void Main() { // Set the connection string and database name string connectionString = "mongodb://localhost:27017"; string databaseName = "your_database_name"; string collectionName = "your_collection_name"; // Create a MongoClient MongoClient client = new MongoClient(connectionString); // Access the database IMongoDatabase database = client.GetDatabase(databaseName); // Access the collection IMongoCollection collection = database.GetCollection(collectionName); // Fetch all documents from the collection var documents = collection.Find(Builders.Filter.Empty).ToCursor(); // Iterate through the documents and print values foreach (var document in documents.ToEnumerable()) { // Assuming your document structure has fields named "Field1", "Field2", etc. Console.WriteLine("Field1: " + document["Field1"]); Console.WriteLine("Field2: " + document["Field2"]); // Add more fields as needed // Print a separator between documents Console.WriteLine(new string('-', 20)); } } }