当前位置: 首页>>代码示例>>C#>>正文


C# MongoGridFS.GetFilesCollection方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:GGsus,项目名称:mongo-csharp-driver,代码行数:28,代码来源:MongoGridFSStream.cs

示例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;
            }
        }
开发者ID:GGsus,项目名称:mongo-csharp-driver,代码行数:36,代码来源:MongoGridFSStream.cs


注:本文中的MongoDB.Driver.GridFS.MongoGridFS.GetFilesCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。