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


C# IMongoDatabase.CreateCollection方法代码示例

本文整理汇总了C#中IMongoDatabase.CreateCollection方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoDatabase.CreateCollection方法的具体用法?C# IMongoDatabase.CreateCollection怎么用?C# IMongoDatabase.CreateCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMongoDatabase的用法示例。


在下文中一共展示了IMongoDatabase.CreateCollection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MongoDBSink

        /// <summary>
        /// Construct a sink posting to a specified database.
        /// </summary>
        /// <param name="database">The MongoDB database.</param>
        /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
        /// <param name="period">The time to wait between checking for event batches.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="collectionName">Name of the MongoDb collection to use for the log. Default is "log".</param>
        /// <param name="collectionCreationOptions">Collection Creation Options for the log collection creation.</param>
        public MongoDBSink(IMongoDatabase database, int batchPostingLimit, TimeSpan period, IFormatProvider formatProvider, string collectionName, CreateCollectionOptions collectionCreationOptions)
            : base(batchPostingLimit, period)
        {
            if (database == null) throw new ArgumentNullException("database");

            _mongoDatabase = database;
            _collectionName = collectionName;
            _collectionCreationOptions = collectionCreationOptions;
            _formatProvider = formatProvider;

            //  capped collections have to be created because GetCollection doesn't offer the option to create one implicitly
            //  only create one if it doesn't already exist
            if (_collectionCreationOptions.Capped.GetValueOrDefault(false)) 
            {
                if (_mongoDatabase.ListCollections(new ListCollectionsOptions 
                {
                    Filter = new BsonDocument {{"name", _collectionName}}
                }).ToList().Count == 0) 
                {
                    _mongoDatabase.CreateCollection(_collectionName, _collectionCreationOptions);
                }
            }
        }
开发者ID:GeneralXception,项目名称:serilog-sinks-mongodb,代码行数:32,代码来源:MongoDBSink.cs

示例2: MongoDBProvider

 public MongoDBProvider()
 {
     _client = new MongoClient("mongodb://" + _settings.dbUser + ":" + _settings.dbPassword + "@" + _settings.mongoDbURL);
     _database = _client.GetDatabase(_settings.mongoDbURL.Substring(_settings.mongoDbURL.LastIndexOf('/') + 1, _settings.mongoDbURL.Length - _settings.mongoDbURL.LastIndexOf('/') - 1));
     _bookmarkCollection = _database.GetCollection<BsonDocument>("bookmarks");
     if (_bookmarkCollection == null)
     {
         _database.CreateCollection("Bookmarks");
     }
 }
开发者ID:prashantkhandelwal,项目名称:DotNetFeeder,代码行数:10,代码来源:MongoDBProvider.cs


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