private static string _connstr = "mongodb://127.0.0.1:27017"; private static string _dbname = "Test"; Const string CollectionName = "Sun";
private static Imongodatabase db { get { var url = new Mongourl (_CONNSTR); var client = new Mongoclient (URL); Return client. Getdatabase (_dbname); } }
Database connection string #region//Get Table object imongocollection<video> TB = db. Getcollection<video> (CollectionName); Delete the current table TB first. Database.dropcollection (CollectionName); Test data---------------------------------var videos = new List<video> {new Video { Title= "The Perfect Developer", category= "SciFi", minutes=118}, new Video {title= "L OST in Frankfurt am Main ", category=" horror ", minutes=122}, new Video {title=" the Infinite standup ", category=" horror ", minutes=341}}; Test data---------------------------------//Insert TB. Insertmany (VIDEOS); Query var all = tb. Find (x = x.title! = string. Empty). ToList (); Packet query var groupby = tb. Aggregate (). Group (x = x.category,g = new {Name = G.key, Count = G.count (), totalminutes = g.sum (x = = x.minutes)}). ToList (); Updated//updating title with "The Perfect developer" video ' s ' title ' and ' minute ' TB. Findoneandupdate (x = X.title = = "The Perfect Developer", Builders<video>. Update.set (x = x.title, "A Perfect Developer [Updated]"). Addtoset (x = x.comments, "Good video!") . Addtoset (x = x.comments, "not bad")); all = TB. Find (x = x.title! = string. Empty). ToList (); Remove TB. Deleteone (x = x.minutes = = 122); all = TB. Find (x = x.title! = string. Empty). ToList (); #endregion
.
It is recommended to use a 2 MongoDB GUI
1, Mongodbcompass
2, Robomongo
64-bit MongoDB installation tools and GUI tools under Windows
Http://pan.baidu.com/s/1c2gqJGO
. NET MongoDB Drivers
Http://pan.baidu.com/s/1eRZ1eNo
MongoDB 3.4 version, C # driver 2.4 operation