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


Python pymongo.MongoClient类代码示例

本文整理汇总了Python中flask.ext.pymongo.MongoClient的典型用法代码示例。如果您正苦于以下问题:Python MongoClient类的具体用法?Python MongoClient怎么用?Python MongoClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: dropDB

    def dropDB(self):
        #return
        # connect to database.
        self.connection = MongoClient(MONGO_URI)

        # drop all tables except the genomic/clinical
        db = self.connection[MONGO_DBNAME]
        db.drop_collection("user")
        db.drop_collection("team")
        db.drop_collection("filter")
        db.drop_collection("match")
        db.drop_collection("hipaa")
        db.drop_collection("status")
        db.drop_collection("trial")
        db.drop_collection("normalize")
        db.drop_collection("email")

        # clear extra clinical and genomic.
        db['clinical'].delete_many({"TOTAL_READS" : 123, "ORD_PHYSICIAN_NPI": 0000})
        db['genomic'].delete_many({'COVERAGE': 9123})
        db['genomic'].delete_many({"STRUCTURAL_VARIANT_COMMENT": re.compile("tmp6654.*", re.IGNORECASE)})
        for id in self.inserted_clinical:
            db['clinical'].delete_one({'_id': ObjectId(id)})
        for id in self.inserted_genomic:
            db['genomic'].delete_one({'_id': ObjectId(id)})

        # last check.
        db['clinical'].delete_many({"SAMPLE_ID": "TCGA-OR-TEST1"})

        # close connection.
        self.connection.close()
开发者ID:dfci,项目名称:matchminer-api,代码行数:31,代码来源:__init__.py

示例2: dropDB

 def dropDB(self):
     settings = self.app.config['MONGODB_SETTINGS']
     self.connection = MongoClient(
         settings['HOST'],
         settings['PORT'])
     self.connection.drop_database(settings['DB'])
     self.connection.close()
开发者ID:kcaylor,项目名称:old_api,代码行数:7,代码来源:__init__.py

示例3: setupDB

 def setupDB(self):
     self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
     self.connection.drop_database(MONGO_DBNAME)
     if MONGO_USERNAME:
         self.connection[MONGO_DBNAME].add_user(MONGO_USERNAME,
                                                MONGO_PASSWORD)
     self.bulk_insert()
开发者ID:Acapla,项目名称:eve,代码行数:7,代码来源:__init__.py

示例4: setupDB

 def setupDB(self):
     self.connection = MongoClient(self.MONGO_HOST, self.MONGO_PORT)
     self.db = self.connection[self.MONGO_DBNAME]
     self.drop_databases()
     self.create_dummy_user()
     self.create_self_machine_account()
     # We call the method again as we have erased the DB
     self.app.grd_submitter_caller = SubmitterCaller(self.app, GRDSubmitter)
开发者ID:eReuse,项目名称:DeviceHub,代码行数:8,代码来源:__init__.py

示例5: setupDB

 def setupDB(self):
     self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
     self.connection.drop_database(MONGO_DBNAME)
     if MONGO_USERNAME:
         self.connection[MONGO_DBNAME].add_user(MONGO_USERNAME,
                                                MONGO_PASSWORD)
     db = self.connection[MONGO_DBNAME]
     self.accounts_insert(db)
     self.company_insert(db)
     db.connection.close()
开发者ID:kidaa,项目名称:adam,代码行数:10,代码来源:__init__.py

示例6: TestMultiMongo

class TestMultiMongo(TestBase):
    def setUp(self):
        super(TestMultiMongo, self).setUp()

        self.setupDB2()

        schema = {
            'author': {'type': 'string'},
            'title': {'type': 'string'},
        }
        settings = {
            'schema': schema,
            'mongo_prefix': 'MONGO1'
        }

        self.app.register_resource('works', settings)

    def tearDown(self):
        super(TestMultiMongo, self).tearDown()
        self.dropDB2()

    def setupDB2(self):
        self.connection = MongoClient()
        self.connection.drop_database(MONGO1_DBNAME)
        self.connection[MONGO1_DBNAME].add_user(MONGO1_USERNAME,
                                                MONGO1_PASSWORD)
        self.bulk_insert2()

    def dropDB2(self):
        self.connection = MongoClient()
        self.connection.drop_database(MONGO1_DBNAME)
        self.connection.close()

    def bulk_insert2(self):
        _db = self.connection[MONGO1_DBNAME]
        works = self.random_works(self.known_resource_count)
        _db.works.insert(works)
        self.work = _db.works.find_one()
        self.connection.close()

    def random_works(self, num):
        works = []
        for i in range(num):
            dt = datetime.now()
            work = {
                'author': self.random_string(20),
                'title': self.random_string(30),
                eve.LAST_UPDATED: dt,
                eve.DATE_CREATED: dt,
            }
            works.append(work)
        return works
开发者ID:kidaa,项目名称:eve,代码行数:52,代码来源:multi_mongo.py

示例7: _setup_db

    def _setup_db(self):

        # connect to database.
        self.connection = MongoClient(self.mongo_uri)

        # make user.
        if self.muser is not None:
            self.connection[self.mongo_dbname].add_user(self.muser, self.mpass)

        # establish the collection interface.
        self._c = self.connection[self.mongo_dbname][self.collection_clinical]
        self._g = self.connection[self.mongo_dbname][self.collection_genomic]
开发者ID:dfci,项目名称:matchminer-api,代码行数:12,代码来源:engine.py

示例8: setupDB

    def setupDB(self):

        # drop the database.
        self.dropDB()

        # connect to database.
        self.connection = MongoClient(MONGO_URI)

        # establish connection.
        if MONGO_USERNAME:
            self.connection[MONGO_DBNAME].add_user(MONGO_USERNAME,
                                                   MONGO_PASSWORD)
开发者ID:dfci,项目名称:matchminer-api,代码行数:12,代码来源:__init__.py

示例9: clear_db_partially

def clear_db_partially():

    logging.warn("dropping all tables in database EXCEPT clinical and genomic")

    # connect to database.
    #connection = MongoClient(MONGO_HOST, MONGO_PORT)
    connection = MongoClient(MONGO_URI)

    # establish connection.
    if MONGO_USERNAME:
        connection[MONGO_DBNAME].add_user(MONGO_USERNAME, MONGO_PASSWORD)

    # setup the db pointer
    db = connection[MONGO_DBNAME]

    # clear the database.
    db.drop_collection("user")
    db.drop_collection("team")
    db.drop_collection("filter")
    db.drop_collection("match")
    connection.close()
开发者ID:dfci,项目名称:matchminer-api,代码行数:21,代码来源:utilities.py

示例10: add_simulated_sv

def add_simulated_sv():

    # connect to database.
    #connection = MongoClient(MONGO_HOST, MONGO_PORT)
    connection = MongoClient(MONGO_URI)

    # setup the db pointer
    db = connection[MONGO_DBNAME]

    # fetch all patients.
    patients = list(db.clinical.find())
    pidx = range(len(patients))

    # loop over each synoymm
    svs = list()
    from matchminer.constants import synonyms
    for key in synonyms:
        for val in synonyms[key]:

            # get clinical_id.
            idx = random.choice(pidx)
            clinical_id = str(patients[idx]['_id'])
            sample_id = str(patients[idx]['SAMPLE_ID'])


            # make a SV.
            sv = {
                'CLINICAL_ID': clinical_id,
                'VARIANT_CATEGORY': 'SV',
                'STRUCTURAL_VARIANT_COMMENT': "tmp6654 " + val,
                'WILDTYPE': False,
                'SAMPLE_ID': sample_id
            }
            svs.append(sv)

    # return it.
    connection.close()
    return svs
开发者ID:dfci,项目名称:matchminer-api,代码行数:38,代码来源:utilities.py

示例11: setupDB

 def setupDB(self):
     settings = self.app.config['MONGODB_SETTINGS']
     self.connection = MongoClient(settings['HOST'],
                                   settings['PORT'])
     self.connection.drop_database(settings['DB'])
     if 'USERNAME' in settings:
         self.connection[settings['DB']].add_user(
             settings['USERNAME'], settings['PASSWORD'])
     self.Pod = models.Pod
     self.User = models.User
     self.Message = models.Message
     self.Notebook = models.Notebook
     self.Sensor = models.Sensor
     self.Data = models.Data
     self.bulk_insert()
开发者ID:kcaylor,项目名称:old_api,代码行数:15,代码来源:__init__.py

示例12: dropDB

 def dropDB(self):
     self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
     self.connection.drop_database(MONGO_DBNAME)
     self.connection.close()
开发者ID:Acapla,项目名称:eve,代码行数:4,代码来源:__init__.py

示例13: dropDB2

 def dropDB2(self):
     self.connection = MongoClient()
     self.connection.drop_database(MONGO1_DBNAME)
     self.connection.close()
开发者ID:kidaa,项目名称:eve,代码行数:4,代码来源:multi_mongo.py

示例14: TestMinimal

class TestMinimal(TestBase):
    def setUp(self):
        """ Prepare the test fixture
        """
        self.setupDB()
        super(TestMinimal, self).setUp()
        self.app = Eve(settings='settings.py', auth=run.Auth)
        self.test_client = self.app.test_client()
        self.domain = self.app.config['DOMAIN']

    def tearDown(self):
        self.dropDB()

    def assert200(self, status):
        self.assertEqual(status, 200)

    def assert301(self, status):
        self.assertEqual(status, 301)

    def assert404(self, status):
        self.assertEqual(status, 404)

    def assert304(self, status):
        self.assertEqual(status, 304)

    def assert400(self, status):
        self.assertEqual(status, 400)

    def assert401(self, status):
        self.assertEqual(status, 401)

    def assert401or405(self, status):
        self.assertTrue(status == 401 or 405)

    def assert403(self, status):
        self.assertEqual(status, 403)

    def assert405(self, status):
        self.assertEqual(status, 405)

    def assert412(self, status):
        self.assertEqual(status, 412)

    def assert500(self, status):
        self.assertEqual(status, 500)

    def setupDB(self):
        self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
        self.connection.drop_database(MONGO_DBNAME)
        if MONGO_USERNAME:
            self.connection[MONGO_DBNAME].add_user(MONGO_USERNAME,
                                                   MONGO_PASSWORD)
        self.bulk_insert()

    def bulk_insert(self):
        accounts = [
            {'u': '[email protected]', 'p': 'pw1', 't': 'token1', 'r': ['app']},
            {'u': '[email protected]', 'p': 'pw1', 't': 'token2', 'r': ['user']},
        ]
        _db = self.connection[MONGO_DBNAME]
        _db.accounts.insert(accounts)
        self.connection.close()

    def dropDB(self):
        self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
        self.connection.drop_database(MONGO_DBNAME)
        self.connection.close()
开发者ID:nicolaiarocci,项目名称:Eve.NET-testbed,代码行数:67,代码来源:tests.py

示例15: TestBase

class TestBase(TestMinimal):
    DEVICES = 'devices'
    DEVICE_EVENT = 'events/devices'
    EVENTS = 'events'
    PLACES = 'places'
    SNAPSHOT = 'snapshot'
    ACCOUNTS = 'accounts'

    def setUp(self, settings_file=None, url_converters=None):
        from ereuse_devicehub import default_settings as settings
        self.set_settings(settings)
        self.app = DeviceHub()
        self.prepare()

    @staticmethod
    def set_settings(settings):
        settings.MONGO_DBNAME = 'devicehubtest'
        settings.DATABASES = 'dht1', 'dht2'  # Some tests use 2 databases
        settings.DHT1_DBNAME = 'dht1_'
        settings.DHT2_DBNAME = 'dht2_'
        settings.GRD_DEBUG = True  # We do not want to actually fulfill GRD
        settings.APP_NAME = 'DeviceHub'
        settings.DEBUG = True
        settings.TESTING = True
        settings.LOG = True
        settings.GRD = False
        settings.AGENT_ACCOUNTS = {
            'self': ('[email protected]', '12345')
        }

    def prepare(self):
        self.MONGO_DBNAME = self.app.config['MONGO_DBNAME']
        self.MONGO_HOST = self.app.config['MONGO_HOST']
        self.MONGO_PORT = self.app.config['MONGO_PORT']
        self.DATABASES = self.app.config['DATABASES']

        self.connection = None
        self.setupDB()

        self.test_client = self.app.test_client()
        self.domain = self.app.config['DOMAIN']

        self.token = self._login()
        self.auth_header = ('authorization', 'Basic ' + self.token)

    def setupDB(self):
        self.connection = MongoClient(self.MONGO_HOST, self.MONGO_PORT)
        self.db = self.connection[self.MONGO_DBNAME]
        self.drop_databases()
        self.create_dummy_user()
        self.create_self_machine_account()
        # We call the method again as we have erased the DB
        self.app.grd_submitter_caller = SubmitterCaller(self.app, GRDSubmitter)
        # self.app.grd_submitter_caller.token = self.app.grd_submitter_caller.prepare_user(self.app)
        # self.app.grd_submitter_caller.process = None

    def create_dummy_user(self):
        self.db.accounts.insert(
            {
                'email': "[email protected]",
                'password': AccountDomain.encrypt_password('1234'),
                'role': 'admin',
                'token': 'NOFATDNNUB',
                'databases': self.app.config['DATABASES'],
                'defaultDatabase': self.app.config['DATABASES'][0],
                '@type': 'Account'
            }
        )
        self.account = self.db.accounts.find_one({'email': '[email protected]'})

    def create_self_machine_account(self):
        email, password = self.app.config['AGENT_ACCOUNTS']['self']
        self.db.accounts.insert(
            {
                'role': 'superuser',
                'token': 'QYADFBPNZZDFJEWAFGGF',
                'databases': self.app.config['DATABASES'],
                '@type': 'Account',
                'email': email,
                'password': AccountDomain.encrypt_password(password)
            }
        )

    def tearDown(self):
        self.dropDB()
        del self.app

    def drop_databases(self):
        self.connection.drop_database(self.MONGO_DBNAME)
        for database in self.DATABASES:
            self.connection.drop_database(self.app.config[database.upper().replace('-', '') + '_DBNAME'])

    def dropDB(self):
        self.drop_databases()
        self.connection.close()

    def full(self, resource_name: str, resource: dict or str or ObjectId) -> dict:
        return resource if type(resource) is dict else self.get(resource_name, '', str(resource))[0]

    def select_database(self, url):
#.........这里部分代码省略.........
开发者ID:eReuse,项目名称:DeviceHub,代码行数:101,代码来源:__init__.py


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