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


C# MongoClient.DropDatabase方法代码示例

本文整理汇总了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));
        }
开发者ID:identy,项目名称:MongOData,代码行数:7,代码来源:TestData.cs

示例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);
            }
        }
开发者ID:4Rebin,项目名称:NBlog,代码行数:27,代码来源:RepositoryTests.cs

示例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;
 }
开发者ID:victorantos,项目名称:MongOData,代码行数:10,代码来源:Database.cs

示例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"));
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:20,代码来源:MongoClientTests.cs

示例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);
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:22,代码来源:MongoClientTests.cs

示例6: DropDatabase

 private void DropDatabase()
 {
     var server = new MongoClient(_connectionString).GetServer();
     server.DropDatabase(_databaseName);
 }
开发者ID:malylemire1,项目名称:Antler,代码行数:5,代码来源:MongoDbStorage.cs

示例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);
 }
开发者ID:identy,项目名称:MongOData,代码行数:9,代码来源:TestData.cs

示例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");
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:70,代码来源:MongoRepositorySpikes.cs

示例9: DropDatabase

 public static void DropDatabase(string connectionString)
 {
     var server = new MongoClient(connectionString).GetServer();
     var db = DatabaseName(connectionString);
     server.DropDatabase(db);
 }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:6,代码来源:MongoDbRepositoryManager.cs


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