protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //allow viewing json in the browser by default GlobalConfiguration.Configuration.Formatters[0].SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); var data= new programs(); var connstr = @"mongodb://*****:*****@ds035607.mongolab.com:35607/revolentdata"; var client = new MongoDB.Driver.MongoClient(connstr); var server = client.GetServer(); var db = server.GetDatabase("revolentdata"); var coll = db.GetCollection<programsProgram>("movies"); var cursor = coll.FindAll(); data.program = cursor.ToList().ToArray(); Application["data"] = data; //factual api info Application["factkey"] = "UVz7N3cX8wHDYon4dHoVfmj8kzYL3sDVJ2SXn8Dl"; Application["factsec"] = "Ok2lXgEde7JazbsbZBMSJ5bYmH0wbTLycB13TUZW"; }
private static MongoDB.Driver.MongoDatabase ConnectToDatabase() { MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient(mongoUrl); var server = client.GetServer(); var db = server.GetDatabase(mongoDatabase); return db; }
protected void Unnamed1_Click(object sender, System.EventArgs e) { string fileName = @"D:\stefan.steiger\Downloads\keywords.xlsx"; MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient("mongodb://localhost/27017/mydb"); MongoDB.Driver.MongoServer server = client.GetServer(); MongoDB.Driver.MongoDatabase database = server.GetDatabase("testdb"); MongoGridFs gridFs = new MongoGridFs(database); MongoDB.Bson.ObjectId id = MongoGridFsUsage.UploadFile(gridFs, fileName); // byte[] baFile = DownloadFile(gridFs, id); // DownloadFile(gridFs, id, @"d:\test.rar"); }
// http://odetocode.com/blogs/scott/archive/2013/04/16/using-gridfs-in-mongodb-from-c.aspx public static void Test() { string fileName = "clip_image071.jpg"; MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient(); MongoDB.Driver.MongoServer server = client.GetServer(); MongoDB.Driver.MongoDatabase database = server.GetDatabase("testdb"); MongoGridFs gridFs = new MongoGridFs(database); MongoDB.Bson.ObjectId id = UploadFile(gridFs, fileName); byte[] baFile = DownloadFile(gridFs, id); DownloadFile(gridFs, id, @"d:\test.rar"); }
// http://odetocode.com/blogs/scott/archive/2013/04/16/using-gridfs-in-mongodb-from-c.aspx public static void Test() { string fileName = "clip_image071.jpg"; MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient(); MongoDB.Driver.MongoServer server = client.GetServer(); MongoDB.Driver.MongoDatabase database = server.GetDatabase("testdb"); MongoGridFs gridFs = new MongoGridFs(database); MongoDB.Bson.ObjectId id = UploadFile(gridFs, fileName); byte[] baFile = DownloadFile(gridFs, id); DownloadFile(gridFs, id, @"d:\test.rar"); } // End Sub Test
public void Mongo000DefaultConnect() { try { Console.WriteLine("Creating client..."); MongoDB.Driver.MongoClient _client = new MongoDB.Driver.MongoClient(); Console.WriteLine("Getting Server..."); MongoDB.Driver.MongoServer _server = _client.GetServer(); Console.WriteLine("Connecting..."); _server.Connect(); Console.WriteLine("Connection Successful."); } catch (Exception exc) { new frmException(exc, "You are not running MongoDB on localhost:27017." + Environment.NewLine + "So it is failing.").ShowDialog(); Console.WriteLine("Connection UnSuccessful."); } }
public void Load_Pricing_List_NotQueryable() { string connectionString = ConfigurationManager.AppSettings["connectionString"].ToString(); string databaseName = "promo"; var client = new MongoDB.Driver.MongoClient(connectionString); var server = client.GetServer(); var database = server.GetDatabase(databaseName); var pricing = database.GetCollection <MOXE.PricingEveryday>("PricingAll_NoFilters"); var cursor = pricing.FindAll(); cursor.SetFields(MongoDB.Driver.Builders.Fields.Include("Identity", "Id")); var items = cursor.ToList(); //var p = PricingClient.LoadList(new ENTITY.Session<ENTITY.NullT>()); //Assert.IsNotNull(p); }
public void Mongo020ConnectClientSettings() { try { Console.WriteLine("Creating client..."); MongoDB.Driver.MongoClient _client = new MongoDB.Driver.MongoClient(new MongoDB.Driver.MongoClientSettings { Server = new MongoDB.Driver.MongoServerAddress(Program.MongoData.Host, Program.MongoData.Port) }); Console.WriteLine("Getting Server..."); MongoDB.Driver.MongoServer _server = _client.GetServer(); Console.WriteLine("Connecting..."); _server.Connect(); Console.WriteLine("Connection Successful."); } catch (Exception exc) { new frmException(exc, "You are not running MongoDB on " + Program.MongoData.Host + ":" + Program.MongoData.Port + "." + Environment.NewLine + "So it is failing.").ShowDialog(); Console.WriteLine("Connection UnSuccessful."); } }
public void Mongo020DB() { try { String connString = "mongodb://" + Program.MongoData.Host + ":" + Program.MongoData.Port; Console.WriteLine("Creating client..."); Console.WriteLine(connString); MongoDB.Driver.MongoClient _client = new MongoDB.Driver.MongoClient(connString); Console.WriteLine("Getting Server..."); MongoDB.Driver.MongoServer _server = _client.GetServer(); Console.WriteLine("Getting database " + Program.MongoData.Database + "..."); MongoDB.Driver.MongoDatabase _database = _server.GetDatabase(Program.MongoData.Database); Console.WriteLine(_database.Name); } catch (Exception exc) { new frmException(exc, "You are not running MongoDB on " + Program.MongoData.Host + ":" + Program.MongoData.Port + "." + Environment.NewLine + "Or you do not have rights to list databases.").ShowDialog(); Console.WriteLine("Connection UnSuccessful."); } }
public void Mongo000ShowDbs() { try { String connString = "mongodb://" + Program.MongoData.Host + ":" + Program.MongoData.Port; Console.WriteLine("Creating client..."); Console.WriteLine(connString); MongoDB.Driver.MongoClient _client = new MongoDB.Driver.MongoClient(connString); Console.WriteLine("Getting Server..."); MongoDB.Driver.MongoServer _server = _client.GetServer(); Console.WriteLine("Connecting..."); String[] databases = _server.GetDatabaseNames().ToArray(); foreach (String db in databases) { Console.WriteLine("\t" + db); } Console.WriteLine(databases.Length + " databases listed."); } catch (Exception exc) { new frmException(exc, "You are not running MongoDB on " + Program.MongoData.Host + ":" + Program.MongoData.Port + "." + Environment.NewLine + "Or you do not have rights to list databases.").ShowDialog(); Console.WriteLine("Connection UnSuccessful."); } }
public void InitializeDatabaseConnection(String connectionString, String dbname) { client = new MongoDB.Driver.MongoClient(connectionString); server = client.GetServer(); Database = server.GetDatabase(dbname); }