Challenge as in stackoverflow
I am struggling with querying the resulting Mongo data imported from a DataTable as shown in the codes below. I can confirm that the data is present in mongo database as shown by the MessageBox output. However, I need some options of code snippet that can retrieve specific information e.g. particular rows - all entries in the row - (from 'batch' or 'collec' mongo components) based on column/field values such as 'var query = new QueryDocument("Column1", "Henry") or ' var filter = Builders<BsonDocument>.Filter.Eq("Column1", "Henry")'. The cases 'collec.Find(query).ToList()' does not pick any entry and 'collec.Find(Filter).ToList()' throws exceptions of invalid arguments in Find(...IMongoQuery)
MongoClient mongo = new MongoClient("mongodb://localhost");
MongoServer server;
MongoDatabase database;
private void Form1_Load(object sender, EventArgs e)
{
server = mongo.GetServer();
server.Connect();
database = server.GetDatabase("test");
List<BsonDocument> batch = new List<BsonDocument>();
foreach (DataRow dr in dt.Rows)
{
var dictionary = dr.Table.Columns.Cast<DataColumn> ().ToDictionary(col => col.ColumnName, col => dr[col.ColumnName]);
batch.Add(new BsonDocument(dictionary));
}
MongoCollection<MongoDB.Bson.BsonDocument> collec = database.GetCollection<BsonDocument>("test");
collec.InsertBatch(batch); //// produces BsonIds for enteries
var results = batch.ToList();
string json = results.ToJson();
MessageBox.Show(json);
////Part I am struggling with
var query = new QueryDocument("Column1", "Henry");
collec.Find(query).ToList(); // THIS DOES NOT PICK ANY RECORD FROM THE DATABASE (SHOWS [])
var filter = Builders<BsonDocument>.Filter.Eq("Column1", "Henry");
collec.Find(Filter).ToList() // THIS ALSO THROWS INVALID ARGUMENT WRT FIND(...)
}
Please examples of using these query options - 'collec.Find(query).ToList()' and 'collec.Find(Filter).ToList() - as mentioned above will be useful.THANKS