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


Python MongoClient.drop_database方法代码示例

本文整理汇总了Python中pymongo.mongo_client.MongoClient.drop_database方法的典型用法代码示例。如果您正苦于以下问题:Python MongoClient.drop_database方法的具体用法?Python MongoClient.drop_database怎么用?Python MongoClient.drop_database使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo.mongo_client.MongoClient的用法示例。


在下文中一共展示了MongoClient.drop_database方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_empty_db_da

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
def get_empty_db_da(_database_name, _json_schema_folders=None, _uri_handlers = None):
    """
    Create an empty database. Drops any existing.

    :param _database_name: The name of the database
    :return: A database access object for the database
    :param _json_schema_folders: A list of application specific JSON schema folders

    """
    _client = MongoClient()
    if _database_name in _client.database_names():
        _client.drop_database(_client[_database_name])
    _database = _client[_database_name]
    return DatabaseAccess(_database=_database, _json_schema_folders=_json_schema_folders, _uri_handlers=_uri_handlers)
开发者ID:OptimalBPM,项目名称:of,代码行数:16,代码来源:init.py

示例2: TestMongosLoadBalancing

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
class TestMongosLoadBalancing(HATestCase):
    def setUp(self):
        super(TestMongosLoadBalancing, self).setUp()
        seed_list = ha_tools.create_sharded_cluster()
        self.assertIsNotNone(seed_list)
        self.dbname = 'pymongo_mongos_ha'
        self.client = MongoClient(
            seed_list,
            serverSelectionTimeoutMS=self.server_selection_timeout)
        self.client.drop_database(self.dbname)

    def test_mongos_load_balancing(self):
        wait_until(lambda: len(ha_tools.routers) == len(self.client.nodes),
                   'discover all mongoses')

        # Can't access "address" when load balancing.
        with self.assertRaises(InvalidOperation):
            self.client.address

        coll = self.client[self.dbname].test
        coll.insert_one({'foo': 'bar'})

        live_routers = list(ha_tools.routers)
        ha_tools.kill_mongos(live_routers.pop())
        while live_routers:
            try:
                self.assertEqual(1, coll.count())
            except ConnectionFailure:
                # If first attempt happened to select the dead mongos.
                self.assertEqual(1, coll.count())

            wait_until(lambda: len(live_routers) == len(self.client.nodes),
                       'remove dead mongos',
                       timeout=30)
            ha_tools.kill_mongos(live_routers.pop())

        # Make sure the last one's really dead.
        time.sleep(1)

        # I'm alone.
        self.assertRaises(ConnectionFailure, coll.count)
        wait_until(lambda: 0 == len(self.client.nodes),
                   'remove dead mongos',
                   timeout=30)

        ha_tools.restart_mongos(one(ha_tools.routers))

        # Find new mongos
        self.assertEqual(1, coll.count())
开发者ID:BiosPsucheZoe,项目名称:mongo-python-driver,代码行数:51,代码来源:test_ha.py

示例3: TestMongosHighAvailability

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
class TestMongosHighAvailability(HATestCase):
    def setUp(self):
        seed_list = ha_tools.create_sharded_cluster()
        self.dbname = 'pymongo_mongos_ha'
        self.client = MongoClient(seed_list)
        self.client.drop_database(self.dbname)

    def test_mongos_ha(self):
        coll = self.client[self.dbname].test
        self.assertTrue(coll.insert({'foo': 'bar'}))

        first = '%s:%d' % (self.client.host, self.client.port)
        ha_tools.kill_mongos(first)
        # Fail first attempt
        self.assertRaises(AutoReconnect, coll.count)
        # Find new mongos
        self.assertEqual(1, coll.count())

        second = '%s:%d' % (self.client.host, self.client.port)
        self.assertNotEqual(first, second)
        ha_tools.kill_mongos(second)
        # Fail first attempt
        self.assertRaises(AutoReconnect, coll.count)
        # Find new mongos
        self.assertEqual(1, coll.count())

        third = '%s:%d' % (self.client.host, self.client.port)
        self.assertNotEqual(second, third)
        ha_tools.kill_mongos(third)
        # Fail first attempt
        self.assertRaises(AutoReconnect, coll.count)

        # We've killed all three, restart one.
        ha_tools.restart_mongos(first)

        # Find new mongos
        self.assertEqual(1, coll.count())

    def tearDown(self):
        self.client.drop_database(self.dbname)
        super(TestMongosHighAvailability, self).tearDown()
开发者ID:nilnullzip,项目名称:mongo-python-driver,代码行数:43,代码来源:test_ha.py

示例4: test_drop_database

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
    def test_drop_database(self):
        client = MongoClient(host, port)

        self.assertRaises(TypeError, client.drop_database, 5)
        self.assertRaises(TypeError, client.drop_database, None)

        raise SkipTest("This test often fails due to SERVER-2329")

        client.pymongo_test.test.save({"dummy": u"object"})
        dbs = client.database_names()
        self.assertTrue("pymongo_test" in dbs)
        client.drop_database("pymongo_test")
        dbs = client.database_names()
        self.assertTrue("pymongo_test" not in dbs)

        client.pymongo_test.test.save({"dummy": u"object"})
        dbs = client.database_names()
        self.assertTrue("pymongo_test" in dbs)
        client.drop_database(client.pymongo_test)
        dbs = client.database_names()
        self.assertTrue("pymongo_test" not in dbs)
开发者ID:quantopian,项目名称:mongo-python-driver,代码行数:23,代码来源:test_client.py

示例5: test_copy_db

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
    def test_copy_db(self):
        c = MongoClient(host, port)
        # Due to SERVER-2329, databases may not disappear
        # from a master in a master-slave pair.
        if server_is_master_with_slave(c):
            raise SkipTest("SERVER-2329")

        ctx = catch_warnings()
        try:
            warnings.simplefilter("ignore", DeprecationWarning)
            self.assertRaises(TypeError, c.copy_database, 4, "foo")
            self.assertRaises(TypeError, c.copy_database, "foo", 4)
            self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")

            c.pymongo_test.test.drop()
            c.pymongo_test.test.insert({"foo": "bar"})

            c.drop_database("pymongo_test1")
            self.assertFalse("pymongo_test1" in c.database_names())

            c.copy_database("pymongo_test", "pymongo_test1")
            self.assertTrue("pymongo_test1" in c.database_names())
            self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
            c.drop_database("pymongo_test1")

            # XXX - SERVER-15318
            if not (version.at_least(c, (2, 6, 4)) and is_mongos(c)):
                self.assertFalse(c.in_request())
                c.copy_database("pymongo_test", "pymongo_test1",
                                "%s:%d" % (host, port))
                # copy_database() didn't accidentally restart the request
                self.assertFalse(c.in_request())

                self.assertTrue("pymongo_test1" in c.database_names())
                self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])

            c.drop_database("pymongo_test1")
        finally:
            ctx.exit()
开发者ID:hedgepigdaniel,项目名称:mongo-python-driver,代码行数:41,代码来源:test_client.py

示例6: get_empty_db_da

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
def get_empty_db_da(_database_name, _json_schema_folder):
    _client = MongoClient()
    if _database_name in _client.database_names():
        _client.drop_database(_client[_database_name])
    _database = _client[_database_name]
    return DatabaseAccess(_json_schema_folder=None,  _database=_database)
开发者ID:OptimalBPM,项目名称:of,代码行数:8,代码来源:test_resources.py

示例7: setUpClass

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
 def setUpClass(cls):
     mongo = MongoClient("mongodb://localhost/")
     mongo.drop_database('ermak-test')
     cls.db = mongo['ermak-test']
开发者ID:leloulight,项目名称:nova-dynamips-driver,代码行数:6,代码来源:rest_test.py

示例8: test_copy_db

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
    def test_copy_db(self):
        c = MongoClient(host, port)
        # Due to SERVER-2329, databases may not disappear
        # from a master in a master-slave pair.
        if server_is_master_with_slave(c):
            raise SkipTest("SERVER-2329")
        # We test copy twice; once starting in a request and once not. In
        # either case the copy should succeed (because it starts a request
        # internally) and should leave us in the same state as before the copy.
        c.start_request()

        self.assertRaises(TypeError, c.copy_database, 4, "foo")
        self.assertRaises(TypeError, c.copy_database, "foo", 4)

        self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")

        c.pymongo_test.test.drop()
        c.drop_database("pymongo_test1")
        c.drop_database("pymongo_test2")
        self.assertFalse("pymongo_test1" in c.database_names())
        self.assertFalse("pymongo_test2" in c.database_names())

        c.pymongo_test.test.insert({"foo": "bar"})

        c.copy_database("pymongo_test", "pymongo_test1")
        # copy_database() didn't accidentally end the request
        self.assertTrue(c.in_request())

        self.assertTrue("pymongo_test1" in c.database_names())
        self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])

        c.end_request()
        self.assertFalse(c.in_request())
        c.copy_database("pymongo_test", "pymongo_test2",
                        "%s:%d" % (host, port))
        # copy_database() didn't accidentally restart the request
        self.assertFalse(c.in_request())

        self.assertTrue("pymongo_test2" in c.database_names())
        self.assertEqual("bar", c.pymongo_test2.test.find_one()["foo"])

        # See SERVER-6427 for mongos
        if (version.at_least(c, (1, 3, 3, 1)) and
            not is_mongos(c) and server_started_with_auth(c)):

            c.drop_database("pymongo_test1")

            c.admin.add_user("admin", "password")
            c.admin.authenticate("admin", "password")
            try:
                c.pymongo_test.add_user("mike", "password")

                self.assertRaises(OperationFailure, c.copy_database,
                                  "pymongo_test", "pymongo_test1",
                                  username="foo", password="bar")
                self.assertFalse("pymongo_test1" in c.database_names())

                self.assertRaises(OperationFailure, c.copy_database,
                                  "pymongo_test", "pymongo_test1",
                                  username="mike", password="bar")
                self.assertFalse("pymongo_test1" in c.database_names())

                c.copy_database("pymongo_test", "pymongo_test1",
                                username="mike", password="password")
                self.assertTrue("pymongo_test1" in c.database_names())
                self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
            finally:
                # Cleanup
                remove_all_users(c.pymongo_test)
                c.admin.remove_user("admin")
                c.disconnect()
开发者ID:quantopian,项目名称:mongo-python-driver,代码行数:73,代码来源:test_client.py

示例9: test_copy_db

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
    def test_copy_db(self):
        c = MongoClient(self.host, self.port)
        # We test copy twice; once starting in a request and once not. In
        # either case the copy should succeed (because it starts a request
        # internally) and should leave us in the same state as before the copy.
        c.start_request()

        self.assertRaises(TypeError, c.copy_database, 4, "foo")
        self.assertRaises(TypeError, c.copy_database, "foo", 4)

        self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")

        c.pymongo_test.test.drop()
        c.drop_database("pymongo_test1")
        c.drop_database("pymongo_test2")

        c.pymongo_test.test.insert({"foo": "bar"})

        # Due to SERVER-2329, databases may not disappear from a master in a
        # master-slave pair
        if not server_is_master_with_slave(c):
            self.assertFalse("pymongo_test1" in c.database_names())
            self.assertFalse("pymongo_test2" in c.database_names())

        c.copy_database("pymongo_test", "pymongo_test1")
        # copy_database() didn't accidentally end the request
        self.assertTrue(c.in_request())

        self.assertTrue("pymongo_test1" in c.database_names())
        self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])

        c.end_request()
        self.assertFalse(c.in_request())
        c.copy_database("pymongo_test", "pymongo_test2",
                        "%s:%d" % (self.host, self.port))
        # copy_database() didn't accidentally restart the request
        self.assertFalse(c.in_request())

        self.assertTrue("pymongo_test2" in c.database_names())
        self.assertEqual("bar", c.pymongo_test2.test.find_one()["foo"])

        if version.at_least(c, (1, 3, 3, 1)):
            c.drop_database("pymongo_test1")

            c.pymongo_test.add_user("mike", "password")

            self.assertRaises(OperationFailure, c.copy_database,
                              "pymongo_test", "pymongo_test1",
                              username="foo", password="bar")
            if not server_is_master_with_slave(c):
                self.assertFalse("pymongo_test1" in c.database_names())

            self.assertRaises(OperationFailure, c.copy_database,
                              "pymongo_test", "pymongo_test1",
                              username="mike", password="bar")

            if not server_is_master_with_slave(c):
                self.assertFalse("pymongo_test1" in c.database_names())

            if not is_mongos(c):
                # See SERVER-6427
                c.copy_database("pymongo_test", "pymongo_test1",
                                username="mike", password="password")
                self.assertTrue("pymongo_test1" in c.database_names())
                self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
开发者ID:DaBbleR23,项目名称:mongo-python-driver,代码行数:67,代码来源:test_client.py

示例10: parse_document

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
    
if __name__ == '__main__':
    return

    root_logger = logging.getLogger('')
    root_logger.setLevel(logging.INFO)
    logFormat = '%(asctime)s %(name)-10s %(levelname)-6s %(message)s'
        
    ch = logging.StreamHandler()
    ch.setFormatter(logging.Formatter(logFormat))
    root_logger.addHandler(ch)
    
    fh = logging.FileHandler('extract.log', mode='w')
    fh.setFormatter(logging.Formatter(logFormat))
    root_logger.addHandler(fh)
    
    logging.getLogger("requests").setLevel(logging.WARNING)
    
    #print parse_document('http://acropolis.org.uk/fb16889287d541ec85534ee7129b85c2.nq')
    #print parse_document('http://acropolis.org.uk/407c1c08ecde41159f1b1b6e91eeaf50.nq')
    #sys.exit(-1)
    
    client = MongoClient()
    client.drop_database('RESplorer')
    db = client['RESplorer']
    
    for (name, uri) in CLASSES.iteritems():
        logger.info('Processing {}'.format(name))
        process_classes(db, uri)

    session_thread.close()
开发者ID:Dans-labs,项目名称:RESplorer,代码行数:33,代码来源:extract.py

示例11: setUp

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import drop_database [as 别名]
 def setUp(self):
     # drop the database before we run the test
     client = MongoClient()
     client.drop_database(settings.MONGODB_DATABASE)
开发者ID:miraculixx,项目名称:minicf,代码行数:6,代码来源:tests.py


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