I have saved files in Mongodb using GridFs and C # but now I need to recover ALL the files I have saved in my database and store them in a folder. I hope you can advise me a little. Thanks
This is the Code as I keep my files
var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("data");
var gridFs = new MongoGridFs(database);
//Este es el archivo que subo a la Base
string ruta = "C:\files\rasta.jpeg";
//Esta parte hace el proceso de carga
using (var file = File.OpenRead(ruta))
{
id = gridFs.AddFile(file, rute);
}
So it shows me the files my Robomongo
What I need is to recover all the files that I have saved in my Base and store it in my "C: /" folder
How do I recover a file ??? I get the id of the last saved file and store it in a MemoryStream
using (var file = gridFs.GetFile(id))
{
var buffer = new byte[file.Length];
string sd = file.Read(buffer, 0, (int)file.Length).ToString();
MemoryStream MS = new MemoryStream(buffer);
}
Once the MemoryStream is obtained it is easy to save my file in my directory, what complicates me is to obtain ALL the files saved in the database and save them in my Folder.
In the bottom part I write how to solve my problem