Reputation: 10281
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?
Upvotes: 7
Views: 3393
Reputation: 76
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)
Upvotes: 5