本文整理汇总了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);
}
}
}
示例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");
}
}