當前位置: 首頁>>代碼示例>>Python>>正文


Python mongo.Mongo類代碼示例

本文整理匯總了Python中eve.io.mongo.Mongo的典型用法代碼示例。如果您正苦於以下問題:Python Mongo類的具體用法?Python Mongo怎麽用?Python Mongo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Mongo類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_combine_queries

 def test_combine_queries(self):
     mongo = Mongo(None)
     query_a = {"username": {"$exists": True}}
     query_b = {"username": "mike"}
     combined = mongo.combine_queries(query_a, query_b)
     self.assertEqual(
         combined, {"$and": [{"username": {"$exists": True}}, {"username": "mike"}]}
     )
開發者ID:sunbit,項目名稱:eve,代碼行數:8,代碼來源:mongo.py

示例2: test_combine_queries

 def test_combine_queries(self):
     mongo = Mongo(None)
     query_a = {'username': {'$exists': True}}
     query_b = {'username': 'mike'}
     combined = mongo.combine_queries(query_a, query_b)
     self.assertEqual(
         combined,
         {'$and': [{'username': {'$exists': True}}, {'username': 'mike'}]}
     )
開發者ID:Arable,項目名稱:evepod,代碼行數:9,代碼來源:mongo.py

示例3: test_get_value_from_query

 def test_get_value_from_query(self):
     mongo = Mongo(None)
     simple_query = {'_id': 'abcdef012345678901234567'}
     compound_query = {'$and': [
         {'username': {'$exists': False}},
         {'_id': 'abcdef012345678901234567'}
     ]}
     self.assertEqual(mongo.get_value_from_query(simple_query, '_id'),
                      'abcdef012345678901234567')
     self.assertEqual(mongo.get_value_from_query(compound_query, '_id'),
                      'abcdef012345678901234567')
開發者ID:AndrewPashkin,項目名稱:eve,代碼行數:11,代碼來源:mongo.py

示例4: test_query_contains_field

 def test_query_contains_field(self):
     mongo = Mongo(None)
     simple_query = {"_id": "abcdef012345678901234567"}
     compound_query = {
         "$and": [
             {"username": {"$exists": False}},
             {"_id": "abcdef012345678901234567"},
         ]
     }
     self.assertTrue(mongo.query_contains_field(simple_query, "_id"))
     self.assertFalse(mongo.query_contains_field(simple_query, "fake-field"))
     self.assertTrue(mongo.query_contains_field(compound_query, "_id"))
     self.assertFalse(mongo.query_contains_field(compound_query, "fake-field"))
開發者ID:sunbit,項目名稱:eve,代碼行數:13,代碼來源:mongo.py

示例5: test_query_contains_field

 def test_query_contains_field(self):
     mongo = Mongo(None)
     simple_query = {'_id': 'abcdef012345678901234567'}
     compound_query = {'$and': [
         {'username': {'$exists': False}},
         {'_id': 'abcdef012345678901234567'}
     ]}
     self.assertTrue(mongo.query_contains_field(simple_query, '_id'))
     self.assertFalse(mongo.query_contains_field(simple_query,
                                                 'fake-field'))
     self.assertTrue(mongo.query_contains_field(compound_query, '_id'))
     self.assertFalse(mongo.query_contains_field(compound_query,
                                                 'fake-field'))
開發者ID:AndrewPashkin,項目名稱:eve,代碼行數:13,代碼來源:mongo.py

示例6: test_get_value_from_query

 def test_get_value_from_query(self):
     mongo = Mongo(None)
     simple_query = {"_id": "abcdef012345678901234567"}
     compound_query = {
         "$and": [
             {"username": {"$exists": False}},
             {"_id": "abcdef012345678901234567"},
         ]
     }
     self.assertEqual(
         mongo.get_value_from_query(simple_query, "_id"), "abcdef012345678901234567"
     )
     self.assertEqual(
         mongo.get_value_from_query(compound_query, "_id"),
         "abcdef012345678901234567",
     )
開發者ID:sunbit,項目名稱:eve,代碼行數:16,代碼來源:mongo.py

示例7: init_app

 def init_app(self, app):
     app.data = self  # app.data must be set for locks to work
     self.mongo = Mongo(app)
     self.driver = self.mongo.driver
     self.storage = self.driver
     self.elastic = Elastic(app, serializer=SuperdeskJSONEncoder(), skip_index_init=True)
     self.init_elastic(app)
開發者ID:akintolga,項目名稱:superdesk-core,代碼行數:7,代碼來源:datalayer.py

示例8: test_json_encoder_class

 def test_json_encoder_class(self):
     mongo = Mongo(None)
     self.assertTrue((mongo.json_encoder_class(), MongoJSONEncoder))
     self.assertTrue((mongo.json_encoder_class(), json.JSONEncoder))
開發者ID:sunbit,項目名稱:eve,代碼行數:4,代碼來源:mongo.py

示例9: SuperdeskDataLayer

class SuperdeskDataLayer(DataLayer):
    """Superdesk Data Layer.

    Implements eve data layer interface, is used to make eve work with superdesk service layer.
    It handles app initialization and later it forwards eve calls to respective service.
    """

    serializers = {}
    serializers.update(Mongo.serializers)
    serializers.update(Elastic.serializers)

    def init_app(self, app):
        app.data = self  # app.data must be set for locks to work
        self.mongo = Mongo(app)
        self.driver = self.mongo.driver
        self.storage = self.driver
        self.elastic = Elastic(app, serializer=SuperdeskJSONEncoder(), skip_index_init=True, retry_on_timeout=True)

    def init_elastic(self, app):
        """Init elastic index.

        It will create index and put mapping. It should run only once so locks are in place.
        Thus mongo must be already setup before running this.
        """
        with app.app_context():
            if lock('elastic', expire=10):
                try:
                    self.elastic.init_index(app)
                finally:
                    unlock('elastic')

    def find(self, resource, req, lookup):
        return superdesk.get_resource_service(resource).get(req=req, lookup=lookup)

    def find_all(self, resource, max_results=1000):
        req = ParsedRequest()
        req.max_results = max_results
        return self._backend(resource).find(resource, req, None)

    def find_one(self, resource, req, **lookup):
        return superdesk.get_resource_service(resource).find_one(req=req, **lookup)

    def find_one_raw(self, resource, _id):
        return self._backend(resource).find_one_raw(resource, _id)

    def find_list_of_ids(self, resource, ids, client_projection=None):
        return self._backend(resource).find_list_of_ids(resource, ids, client_projection)

    def insert(self, resource, docs, **kwargs):
        return superdesk.get_resource_service(resource).create(docs, **kwargs)

    def update(self, resource, id_, updates, original):
        return superdesk.get_resource_service(resource).update(id=id_, updates=updates, original=original)

    def update_all(self, resource, query, updates):
        datasource = self.datasource(resource)
        driver = self._backend(resource).driver
        collection = driver.db[datasource[0]]
        return collection.update(query, {'$set': updates}, multi=True)

    def replace(self, resource, id_, document, original):
        return superdesk.get_resource_service(resource).replace(id=id_, document=document, original=original)

    def remove(self, resource, lookup=None):
        if lookup is None:
            lookup = {}
        return superdesk.get_resource_service(resource).delete(lookup=lookup)

    def is_empty(self, resource):
        return self._backend(resource).is_empty(resource)

    def _search_backend(self, resource):
        if resource.endswith(current_app.config['VERSIONS']):
            return
        datasource = self.datasource(resource)
        backend = config.SOURCES.get(datasource[0], {}).get('search_backend', None)
        return getattr(self, backend) if backend is not None else None

    def _backend(self, resource):
        datasource = self.datasource(resource)
        backend = config.SOURCES.get(datasource[0], {'backend': 'mongo'}).get('backend', 'mongo')
        return getattr(self, backend)

    def get_mongo_collection(self, resource):
        return self.mongo.pymongo('users').db[resource]
開發者ID:hlmnrmr,項目名稱:superdesk-core,代碼行數:85,代碼來源:datalayer.py


注:本文中的eve.io.mongo.Mongo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。