|
The GridFS API lets you provide custom metadata when the file is first uploaded. But the GridFS API does not provide any way to update the metadata after the file has been uploaded.
However, the metadata is stored in the fs.files collection (note: replace fs with your bucket name if you used a custom bucket name), which is a collection like any other. The contents of the fs.files collection are described in the definition of "Files collection document" here:
https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst#terms
As long as you are careful not to disturb the other fields you can update the metadata directly using a regular update statement.
Something like this:
var filesCollection = database.GetCollection<BsonDocument>("fs.files");
|
var filter = Builders<BsonDocument>.Filter.Eq("_id", fileId);
|
var update = Builders<BsonDocument>.Update.Set("metadata", metadata);
|
filesCollection.UpdateOne(filter, update);
|
|