本文整理汇总了C#中MongoDB.Driver.GridFS.MongoGridFS.GetFilesCollection方法的典型用法代码示例。如果您正苦于以下问题:C# MongoGridFS.GetFilesCollection方法的具体用法?C# MongoGridFS.GetFilesCollection怎么用?C# MongoGridFS.GetFilesCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.GridFS.MongoGridFS
的用法示例。
在下文中一共展示了MongoGridFS.GetFilesCollection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateMetadata
private void UpdateMetadata()
{
using (_fileInfo.Server.RequestStart(null, ReadPreference.Primary))
{
var gridFS = new MongoGridFS(_fileInfo.Server, _fileInfo.DatabaseName, _fileInfo.GridFSSettings);
var database = gridFS.GetDatabase(ReadPreference.Primary);
var filesCollection = gridFS.GetFilesCollection(database);
BsonValue md5 = BsonNull.Value;
if (_updateMD5)
{
var md5Command = new CommandDocument
{
{ "filemd5", _fileInfo.Id },
{ "root", gridFS.Settings.Root }
};
var md5Result = database.RunCommand(md5Command);
md5 = md5Result.Response["md5"].AsString;
}
var query = Query.EQ("_id", _fileInfo.Id);
var update = Update
.Set("length", _length)
.Set("md5", md5);
filesCollection.Update(query, update);
}
}
示例2: OpenCreate
private void OpenCreate()
{
EnsureServerInstanceIsPrimary();
using (_fileInfo.Server.RequestStart(null, _fileInfo.ServerInstance))
{
var gridFS = new MongoGridFS(_fileInfo.Server, _fileInfo.DatabaseName, _fileInfo.GridFSSettings);
var database = gridFS.GetDatabase(ReadPreference.Primary);
var filesCollection = gridFS.GetFilesCollection(database);
gridFS.EnsureIndexes();
_fileIsDirty = true;
if (_fileInfo.Id == null)
{
_fileInfo.SetId(ObjectId.GenerateNewId());
}
var aliases = (_fileInfo.Aliases != null) ? new BsonArray(_fileInfo.Aliases) : null;
var file = new BsonDocument
{
{ "_id", _fileInfo.Id },
{ "filename", _fileInfo.Name, !string.IsNullOrEmpty(_fileInfo.Name) },
{ "length", 0 },
{ "chunkSize", _fileInfo.ChunkSize },
{ "uploadDate", _fileInfo.UploadDate },
{ "md5", BsonNull.Value }, // will be updated when the file is closed (unless UpdateMD5 is false)
{ "contentType", _fileInfo.ContentType, !string.IsNullOrEmpty(_fileInfo.ContentType) }, // optional
{ "aliases", aliases, aliases != null }, // optional
{ "metadata", _fileInfo.Metadata, _fileInfo.Metadata != null } // optional
};
filesCollection.Insert(file);
_length = 0;
_position = 0;
}
}