小编use*_*851的帖子

Google App Engine数据存储区中最高效的一对多关系?

对不起,如果这个问题太简单了; 我只进入了9年级.

我正在尝试了解NoSQL数据库设计.我想设计一个最小化读/写次数的Google Datastore模型.

这是博客文章的玩具示例和一对多关系中的评论.哪个更有效 - 将所有注释存储在StructuredProperty中或使用Comment模型中的KeyProperty?

同样,目标是最小化对数据存储的读/写次数.您可以做出以下假设:

  • 不会独立于各自的博客文章检索评论.(我怀疑这使得StructuredProperty最受欢迎.)
  • 注释需要按日期,评级,作者等进行排序.(数据存储区中的子属性无法编入索引,因此可能会影响性能?)
  • 创建后,博客文章和评论都可以编辑(甚至删除).

使用StructuredProperty:

from google.appengine.ext import ndb

class Comment(ndb.Model):
    various properties...

class BlogPost(ndb.Model):
    comments = ndb.StructuredProperty(Comment, repeated=True)
    various other properties...
Run Code Online (Sandbox Code Playgroud)

使用KeyProperty:

from google.appengine.ext import ndb

class BlogPost(ndb.Model):
    various properties...

class Comment(ndb.Model):
    blogPost = ndb.KeyProperty(kind=BlogPost)
    various other properties...
Run Code Online (Sandbox Code Playgroud)

请尽量提出与有效表示一对多关系相关的任何其他注意事项,以尽量减少对数据存储区的读/写次数.

谢谢.

google-app-engine one-to-many nosql app-engine-ndb google-cloud-datastore

16
推荐指数
1
解决办法
4098
查看次数