本文整理汇总了C#中MongoDB.Driver.MongoClient.DropDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# MongoClient.DropDatabase方法的具体用法?C# MongoClient.DropDatabase怎么用?C# MongoClient.DropDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.MongoClient
的用法示例。
在下文中一共展示了MongoClient.DropDatabase方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clean
public static void Clean()
{
var connectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString;
var server = new MongoClient(connectionString).GetServer();
server.DropDatabase(GetDatabaseName(connectionString));
}
示例2: TestCleanup
public void TestCleanup()
{
var repositoryType = Instance.GetType();
if (repositoryType == typeof(JsonRepository))
{
if (Directory.Exists(JsonWorkingFolder))
{
Directory.Delete(JsonWorkingFolder, recursive: true);
}
}
else if (repositoryType == typeof(SqlRepository))
{
using (var cnn = new SqlConnection(SqlConnectionString))
using (var cmd = new SqlCommand("EXEC sp_MSforeachtable @command1 = 'TRUNCATE TABLE ?'", cnn))
{
cnn.Open();
cnn.ChangeDatabase(SqlDatabaseName);
cmd.ExecuteNonQuery();
}
}
else if (repositoryType == typeof(MongoRepository))
{
var server = new MongoClient(MongoConnectionString).GetServer();
server.DropDatabase(MongoDatabaseName);
}
}
示例3: Create
public static Database Create(int protocolVersion, string connectionString)
{
var databaseName = GetDatabaseName(connectionString);
var server = new MongoClient(connectionString).GetServer();
server.DropDatabase(databaseName);
var database = new Database();
database.mongoDatabase = server.GetDatabase(databaseName);
database.protocolVersion = protocolVersion;
return database;
}
示例4: DropDatabase_should_invoke_the_correct_operation
public void DropDatabase_should_invoke_the_correct_operation(
[Values(false, true)] bool async)
{
var operationExecutor = new MockOperationExecutor();
var client = new MongoClient(operationExecutor);
if (async)
{
client.DropDatabaseAsync("awesome").GetAwaiter().GetResult();
}
else
{
client.DropDatabase("awesome");
}
var call = operationExecutor.GetWriteCall<BsonDocument>();
call.Operation.Should().BeOfType<DropDatabaseOperation>();
((DropDatabaseOperation)call.Operation).DatabaseNamespace.Should().Be(new DatabaseNamespace("awesome"));
}
示例5: DropDatabase_should_invoke_the_correct_operation
public void DropDatabase_should_invoke_the_correct_operation(
[Values(false, true)] bool async)
{
var operationExecutor = new MockOperationExecutor();
var writeConcern = new WriteConcern(1);
var client = new MongoClient(operationExecutor, new MongoClientSettings()).WithWriteConcern(writeConcern);
if (async)
{
client.DropDatabaseAsync("awesome").GetAwaiter().GetResult();
}
else
{
client.DropDatabase("awesome");
}
var call = operationExecutor.GetWriteCall<BsonDocument>();
var dropDatabaseOperation = call.Operation.Should().BeOfType<DropDatabaseOperation>().Subject;
dropDatabaseOperation.DatabaseNamespace.Should().Be(new DatabaseNamespace("awesome"));
dropDatabaseOperation.WriteConcern.Should().BeSameAs(writeConcern);
}
示例6: DropDatabase
private void DropDatabase()
{
var server = new MongoClient(_connectionString).GetServer();
server.DropDatabase(_databaseName);
}
示例7: GetDatabase
private static MongoDatabase GetDatabase(bool clear)
{
var connectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString;
var databaseName = GetDatabaseName(connectionString);
var server = new MongoClient(connectionString).GetServer();
if (clear)
server.DropDatabase(databaseName);
return server.GetDatabase(databaseName);
}
示例8: MongoDb_Supports_Basic_Crud_Operations
public void MongoDb_Supports_Basic_Crud_Operations()
{
const string connectionString = "mongodb://localhost";
if (!MongoDbRepositoryManager.ServerIsRunning(connectionString))
{
AssertIgnores.MongoServerIsNotRunning();
}
var server = new MongoClient(connectionString).GetServer();
var databaseNames = server.GetDatabaseNames();
foreach (var db in databaseNames)
{
server.DropDatabase(db);
}
var database = server.GetDatabase("Order");
var orders = database.GetCollection<Order>("Order");
Console.WriteLine("* CREATE *");
var create = new Order { Name = "Big sale" };
database.GetCollection<Order>("Order").Insert(create);
foreach (var order in database.GetCollection<Order>("Order").AsQueryable())
{
Console.WriteLine(order.Name + ", " + order.OrderId);
}
Console.WriteLine("* READ *");
var read = orders.AsQueryable().FirstOrDefault(e => e.OrderId == create.OrderId);
read.Name.ShouldEqual(create.Name);
Console.WriteLine("* UPDATE *");
read.Name = "Really big sale";
database.GetCollection<Order>("Order").Save(read);
foreach (var order in database.GetCollection<Order>("Order").AsQueryable())
{
Console.WriteLine(order.Name + ", " + order.OrderId);
}
var update = database.GetCollection<Order>("Order").AsQueryable().FirstOrDefault(e => e.OrderId == read.OrderId);
update.OrderId.ShouldEqual(read.OrderId);
update.Name.ShouldEqual(read.Name);
Console.WriteLine("* DELETE *");
var delete = database.GetCollection<Order>("Order").AsQueryable().FirstOrDefault(e => e.OrderId == update.OrderId);
database.GetCollection<Order>("Order").Remove(Query.EQ("OrderId", delete.OrderId));
foreach (var order in database.GetCollection<Order>("Order").AsQueryable())
{
Console.WriteLine(order.Name + ", " + order.OrderId);
}
database.GetCollection<Order>("Order").RemoveAll();
Console.WriteLine("* DELETE ALL *");
foreach (var order in database.GetCollection<Order>("Order").AsQueryable())
{
Console.WriteLine(order.Name + ", " + order.OrderId);
}
server.DropDatabase("Order");
}
示例9: DropDatabase
public static void DropDatabase(string connectionString)
{
var server = new MongoClient(connectionString).GetServer();
var db = DatabaseName(connectionString);
server.DropDatabase(db);
}