7

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?

4

1 回答 1

5

mongodb 不支持这个。我认为您可以先删除具有相同名称的文件。就像:

server[dbName].GridFS.Delete(FileName);
server[dbName].GridFS.Upload(localName, FileName)
于 2011-11-10T05:15:43.657 回答