Most Efficient One-To-Many Relationships in Google App Engine Datastore?

后端 未结 3 1135
耶瑟儿~
耶瑟儿~ 2021-02-04 05:28

Sorry if this question is too simple; I\'m only entering 9th grade.

I\'m trying to learn about NoSQL database design. I want to design a Google Datastore model that min

3条回答
  •  别那么骄傲
    2021-02-04 06:11

    What about:

    from google.appengine.ext import ndb
    
    class Comment(ndb.Model):
        various properties...
    
    class BlogPost(ndb.Model):
        comments = ndb.KeyProperty(Comment, repeated=True)
        various other properties...
    

    This way, you can store up to 5000 comments per blog post (the maximum number of repeated properties) independent of the size of each blog post. You won't need a query to fetch the blogs for a comment, you can just do ndb.get_multi(blog_post.comments). And for this operation, you can try to rely on ndb's memcache. Of course, it depends on your use case whether this is a good assumption or not.

提交回复
热议问题