0

I'M trying to list all documents in a collection with mongodb and c#. Insert and delete performance is good. But when I try to list all items in a table (collection) mongo db just select 3000 row in a second. (By the way Sql Server express 200k in a second, mysql 111k, oracle express 111k, postgresql 91k and firebird 63k)

This is my select code.

var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("testdb1");
var collection = database.GetCollection<Entity>("tablo1");

var entity = collection.FindAll();

foreach (var deger in collection.FindAll())
{
    string[] row1 = new string[] { deger.deger1.ToString() };
    dataGridView1.Rows.Add(row1);
    Application.DoEvents();
}

Does anyone know better way to list all records to datagridview?

This is how i list with all other database systems.

NpgsqlDataAdapter dataadapter = new NpgsqlDataAdapter("SELECT * FROM tablo1", baglanti1);
DataSet ds = new DataSet();
baglanti1.Open();
dataadapter.Fill(ds, "tablo1");
baglanti1.Close();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "tablo1";

Can I use dataset and dataadapter with MongoDB?

slavoo
  • 5,798
  • 64
  • 37
  • 39
Hakkı
  • 811
  • 2
  • 13
  • 23

1 Answers1

1

Solved.

var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("testdb1");
var collection = database.GetCollection<Entity>("tablo1");

//var entity = collection.FindAll();

BindingList<Entity> doclist = new BindingList<Entity>();

foreach (var deger in collection.FindAll())
{
    doclist.Add(deger);
    //string[] row1 = new string[] { deger.deger1.ToString() };
    //dataGridView1.Rows.Add(row1);
    Application.DoEvents();
}
dataGridView1.DataSource = doclist;

My Entity Class

public class Entity
{
    public ObjectId Id { get; set; }
    public string deger1 { get; set; }
}

And add these libraries

using MongoDB.Driver;
using MongoDB.Bson;
using MongoDB.Driver.Linq;
using System.ComponentModel;

Source Update mongodb database when datagridview is changed

slavoo
  • 5,798
  • 64
  • 37
  • 39
Hakkı
  • 811
  • 2
  • 13
  • 23