Google数据存储区建模

时间:2015-08-08 04:16:44

标签: python google-app-engine google-cloud-datastore

我正在设计一个存储在Google Datastore中的数据结构。

  1. 应用程序有类别
  2. 类别具有其他属性
  3. 我想查询属于特定类别的所有应用程序 我还希望得到给定类别中应用程序数量的总和。

    为实现这一目标,我设计了以下课程。

    application.py

    from google.appengine.ext import ndb
    from cfc.models.admin.applicationcategory import ApplicationCategory
    
    class Application(ndb.model):
        """ Application Model"""
        name = ndb.StringProperty()
        category = ApplicationCategory()
    

    applicationcategory.py

    from google.appengine.ext import ndb
    
    class ApplicationCategory(ndb.model):
        """Models an application Category"""
        name = ndb.StringProperty()
        date_created = ndb.DateTimeProperty(auto_now_add=True)
    

    我的问题是如何定义查询,数据存储最终是一致的?

1 个答案:

答案 0 :(得分:1)

数据存储未针对此类方案进行优化。根据给定类别获取应用程序计数的最佳选择是使用search api。为每个应用程序创建一个文档,并将类别添加为构面。然后,您可以使用分面搜索来使用构面值查询来获取计数。