本文整理汇总了C#中IMongoDatabase.DropCollectionAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoDatabase.DropCollectionAsync方法的具体用法?C# IMongoDatabase.DropCollectionAsync怎么用?C# IMongoDatabase.DropCollectionAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMongoDatabase
的用法示例。
在下文中一共展示了IMongoDatabase.DropCollectionAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeforeEachTest
public void BeforeEachTest()
{
var client = new MongoClient("mongodb://localhost:27017");
var identityTesting = "identity-testing";
Database = client.GetDatabase(identityTesting);
Users = Database.GetCollection<IdentityUser>("users");
Roles = Database.GetCollection<IdentityRole>("roles");
DatabaseNewApi = client.GetDatabase(identityTesting);
_UsersNewApi = DatabaseNewApi.GetCollection<IdentityUser>("users");
_RolesNewApi = DatabaseNewApi.GetCollection<IdentityRole>("roles");
Database.DropCollectionAsync("users").Wait();
Database.DropCollectionAsync("roles").Wait();
}
示例2: SetUp
public void SetUp()
{
GlobalContext.Properties.Clear();
ThreadContext.Properties.Clear();
MongoUrl url = new MongoUrl("mongodb://localhost/log4net");
MongoClient client = new MongoClient(url);
_db = client.GetDatabase(url.DatabaseName);
_db.DropCollectionAsync(LogsCollectionName);
_collection = _db.GetCollection<BsonDocument>(LogsCollectionName);
}
示例3: InsertStudentScore
public static async void InsertStudentScore(IMongoDatabase db)
{
var jsonPath = @"C:\Codec\MongoDB\Uni\homework_3_1\students.json";
var collectionName = "studentscore";
try
{
await db.DropCollectionAsync(collectionName);
var collection = db.GetCollection<StudentScore>(collectionName);
using (var streamReader = new StreamReader(jsonPath))
{
string line;
while ((line = await streamReader.ReadLineAsync()) != null)
{
using (var jsonReader = new JsonReader(line))
{
var context = BsonDeserializationContext.CreateRoot(jsonReader);
var document = collection.DocumentSerializer.Deserialize(context);
await collection.InsertOneAsync(document);
}
}
}
Console.WriteLine("Successfully Uploaded Students Score");
Console.WriteLine("Querying all documents");
await QueryAllDocuments(db, collectionName);
QueryLowestScore(db, collectionName);
}
catch (Exception ex)
{
Console.WriteLine("Exception \n\n");
Console.WriteLine(ex.Message);
}
}
示例4: InsertGrades
public static async void InsertGrades(IMongoDatabase db)
{
string jsonPath = @"C:\Codec\MongoDB\Uni\week_2_crud.bf5486e303a0\homework_2_1\grades.json";
try
{
await db.DropCollectionAsync("grades");
var collection = db.GetCollection<Grades>("grades");
using (var streamReader = new StreamReader(jsonPath))
{
string line;
while ((line = await streamReader.ReadLineAsync()) != null)
{
using (var jsonReader = new JsonReader(line))
{
var context = BsonDeserializationContext.CreateRoot(jsonReader);
var document = collection.DocumentSerializer.Deserialize(context);
await collection.InsertOneAsync(document);
}
}
}
Console.WriteLine("Successfully Uploaded Grades");
Console.WriteLine("Querying all documents");
await QueryAllDocuments(db, "grades");
}
catch (Exception ex)
{
Console.WriteLine("Exception \n\n");
Console.WriteLine(ex.Message);
}
}