How To Make Connection With MongoDb Using C# Asp.net - OmIndia

Teach To India

Friday, August 11, 2017

How To Make Connection With MongoDb Using C# Asp.net

How To Make Connection With MongoDb Using C# Asp.net


String connectionString = "mongodb://localhost";
                MongoClient client = new MongoClient(connectionString);
                MongoServer mdb= client.GetServer();
                MongoDatabase database = mdb.MongoConnections("NetCrawlerDemo");
                MongoCollection collection = database.GetCollection<"SGATableFind">("DA_TrackerInfo_SGA");

                MongoCursor<"BsonDocument"> cursor = collection.FindAllAs<"BsonDocument">();


                DataTable dt = new DataTable();
                dt.Columns.Add("_id", typeof(MongoDB.Bson.ObjectId));
                dt.Columns.Add("DA_TrackerID", typeof(Int32));
                dt.Columns.Add("DA_Group", typeof(string));
                dt.Columns.Add("DA_SubGroup", typeof(string));
                dt.Columns.Add("DA_SearchEngine", typeof(string));
                dt.Columns.Add("DA_WebSiteURL", typeof(string));
                dt.Columns.Add("DA_ArticleHeader", typeof(string));
                dt.Columns.Add("DA_ArticleDescription", typeof(string));
                dt.Columns.Add("DA_ArticleDetails", typeof(string));
                dt.Columns.Add("DA_CompanyName", typeof(string));
                dt.Columns.Add("DA_AdditionalKeyword", typeof(string));
                dt.Columns.Add("DA_ArticleDateTime", typeof(string));
                dt.Columns.Add("DA_ArticleYear", typeof(string));
                dt.Columns.Add("DA_ArticleMonth", typeof(string));
                dt.Columns.Add("DA_ArticleDay", typeof(string));
                dt.Columns.Add("DA_DateTime", typeof(DateTime));

                foreach (var item in cursor)
                {
                    dt.Rows.Add(item["_id"], item["DA_TrackerID"], item["DA_Group"], item["DA_SubGroup"], item["DA_SearchEngine"],
                        item["DA_WebSiteURL"], item["DA_ArticleHeader"], item["DA_ArticleDescription"], item["DA_ArticleDetails"], item["DA_CompanyName"]
                        , item["DA_AdditionalKeyword"], item["DA_ArticleDateTime"], item["DA_ArticleYear"], item["DA_ArticleMonth"], item["DA_ArticleDay"]
                        , item["DA_DateTime"]);
                }

                grid1.DataSource = dt;



mongo c# connection string
mongo c# contains
mongo c# count
mongo c# create index
mongo c# cursor
mongo c# distinct
mongo c# driver 1.10
mongo c# driver example
mongo c# driver github

3 comments:

Comments

Popular