I am writing to the MongoDB gridfs using the following code:
MongoDB.Driver.GridFS.MongoGridFSCreateOptions createOptions = new MongoDB.Driver.GridFS.MongoGridFSCreateOptions();
createOptions.ContentType = Helper.GetFileExtensionFromFilename(clientToSave.LogoFilename);
var gridFsInfo = adminDB.GridFS.Upload(clientToSave.LogoStream, clientToSave.DatabaseName, createOptions);
When I look into Gridfs I can see that files seem to be being added, so I'm ending up with lots of files with the same name. When I read the gridfs it always returns the latest file, so it all works ok, but it seems rather inefficient.
How do I perform a MongoDB gridfs write that overwrites any exiting file with the same name?
mongodb does not support this. I think you can delete file with the same name first .just like:
server[dbName].GridFS.Delete(FileName);
server[dbName].GridFS.Upload(localName, FileName)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With