Created
December 12, 2012 20:01
-
-
Save g0t4/4271057 to your computer and use it in GitHub Desktop.
Mongodb editing file information with c# driver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Easier to just pull the file collection and edit the files documents, just be careful, example: | |
public void SaveMetadata(string id, MetadataJson metadata) | |
{ | |
var gridFs = FilesContext.GetGridFs(); | |
var files = gridFs.Database.GetCollection(gridFs.Settings.FilesCollectionName); | |
var file = files.FindOneById(new BsonObjectId(id)); | |
var metadataDocument = file["metadata"].AsBsonDocument; | |
metadataDocument.Set("comment", metadata.comment ?? string.Empty); | |
if (metadata.name.IsNotNullOrWhiteSpace()) | |
{ | |
file.Set("filename", metadata.name); | |
} | |
files.Save(file); | |
} | |
public class MetadataJson | |
{ | |
public string name { get; set; } | |
public string comment { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment