本文整理汇总了C#中IMongoDatabase.CreateCollectionAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoDatabase.CreateCollectionAsync方法的具体用法?C# IMongoDatabase.CreateCollectionAsync怎么用?C# IMongoDatabase.CreateCollectionAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMongoDatabase
的用法示例。
在下文中一共展示了IMongoDatabase.CreateCollectionAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: firstTimeInstallDataBase
private async void firstTimeInstallDataBase (IMongoDatabase database, string rootPath){
try {
if (!CollectionExistsAsync (database, "actors").Result) {
await database.CreateCollectionAsync ("actors");
var actors = new ActorRepository();
foreach (Actor actor in actors.Retrieve(rootPath))
{
var collectionActors = database.GetCollection<Actor>("actors");
await collectionActors.InsertOneAsync(actor);
}
}
if (!CollectionExistsAsync (database, "movies").Result) {
await database.CreateCollectionAsync ("movies");
var movies = new MovieRepository();
foreach (Movie movie in movies.Retrieve(rootPath))
{
var collectionActors = database.GetCollection<Movie>("movies");
await collectionActors.InsertOneAsync(movie);
}
}
}
catch {
throw;
}
}
示例2: FullTextSearch
public FullTextSearch(string databaseName = "test", MongoUrl url = null)
{
mongoClient = url == null ? new MongoClient() : new MongoClient(url);
database = mongoClient.GetDatabase(databaseName);
database.CreateCollectionAsync("Students").Wait();
}
示例3: CreateCollection
private void CreateCollection(IMongoDatabase db, string collectionName)
{
var cob = new CreateCollectionOptions();
SetCappedCollectionOptions(cob);
db.CreateCollectionAsync(collectionName, cob).GetAwaiter().GetResult();
}
示例4: CreateCollectionAsync
private static async Task CreateCollectionAsync(IMongoDatabase mongoDatabase, string collectionName, long? cappedCollectionSize, long? maxNumberOfDocuments)
{
var createCollectionOptions = new CreateCollectionOptions()
{
Capped = true,
MaxSize = cappedCollectionSize ?? DefaultCappedCollectionSize,
MaxDocuments = maxNumberOfDocuments ?? DefaultCappedCollectionMaxDocuments
};
await mongoDatabase.CreateCollectionAsync(collectionName ?? CollectionDefaulName, createCollectionOptions);
}
示例5: MongoDBClient
public MongoDBClient(string _collection)
{
this.connectionString = "mongodb://groupeNoSql3:[email protected]:55564/stockexchange";
//mongo ds055564.mongolab.com:55564/stockexchange -u groupeNoSql3 -p groupeNoSql3
client = new MongoClient(this.connectionString);
database = client.GetDatabase("stockexchange");
this.collection = database.GetCollection<BsonDocument>(_collection);
if (this.collection == null) database.CreateCollectionAsync(_collection);
}