简体   繁体   English

如何覆盖MongoDB Gridfs中的文件?

[英]How do I overwrite a file in MongoDB Gridfs?

I am writing to the MongoDB gridfs using the following code: 我使用以下代码写入MongoDB gridfs:

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. 当我查看Gridfs时,我可以看到文件似乎被添加,所以我最终得到了许多具有相同名称的文件。 When I read the gridfs it always returns the latest file, so it all works ok, but it seems rather inefficient. 当我读取gridfs它总是返回最新的文件,所以一切正常,但它看起来效率很低。

How do I perform a MongoDB gridfs write that overwrites any exiting file with the same name? 如何执行覆盖任何具有相同名称的现有文件的MongoDB gridfs写入?

mongodb does not support this. mongodb不支持这个。 I think you can delete file with the same name first .just like: 我想你可以先删除同名的文件。就像:

server[dbName].GridFS.Delete(FileName);
server[dbName].GridFS.Upload(localName, FileName)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM