Answers for "Mongo Find all documents"

C#
0

Mongo Find all documents

using System;
using MongoDB.Driver;
using MongoDB.Bson;

namespace FindAll
{
    class Program
    {
        static void Main(string[] args)
        {
            var dbClient = new MongoClient("mongodb://127.0.0.1:27017");
            IMongoDatabase db = dbClient.GetDatabase("testdb");

            var cars = db.GetCollection<BsonDocument>("cars");
            var documents = cars.Find(new BsonDocument()).ToList();

            foreach (BsonDocument doc in documents)
            {
                Console.WriteLine(doc.ToString());
            }
        }
    }
}
Posted by: Guest on October-13-2021

Code answers related to "Mongo Find all documents"

C# Answers by Framework

Browse Popular Code Answers by Language