c# Mongo db FindAll()

本文关键字:FindAll db Mongo | 更新日期: 2023-09-27 18:24:42

我是MongoDB和C#的新手。我不知道如何从我的收藏"kljenti"中获取所有数据。

有人能帮我吗?

下面是我的代码

 public void getAllData() {
 try {
     string connectionString = "mongodb://172.16.1.24:27017";
     MongoClient client = null;
     client = new MongoClient(connectionString);
     MongoServer server = null;
     server = client.GetServer();
     MongoDatabase database = null;
     database = server.GetDatabase("kljenti");
     var Client = new MongoClient();
     var DB = Client.GetDatabase("knjigoMata");
     var collection = DB.GetCollection<BsonDocument>("kljenti");
     MongoCursor < BsonDocument > cursor = collection.FindAllAs<BsonDocument>();
     } 
catch{
     MessageBox.Show("Nemogu prikazati podatke o korisnicima");
      }

c# Mongo db FindAll()

它应该类似于:

var allDocuments=集合。查找(新BsonDocument()).ToListAsync().Result;