Schema-less design guidelines for Google App Engine Datastore and other NoSQL DBs

最后都变了- 提交于 2019-12-03 12:21:14

问题


Coming from a relational database background, as I'm sure many others are, I'm looking for some solid guidelines for setting up / designing my datastore on Google App Engine. Are there any good rules of thumb people have for setting up these kinds of schema-less data stores? I understand some of the basics such as denormalizing since you can't do joins, but I was wondering what other recommendations people had.

The particular simple example I am working with concerns storing searches and their results. For example I have the following two models defined in my Google App Engine app using Python:

class Search(db.Model):
    who = db.StringProperty()
    what = db.StringProperty()
    where = db.StringProperty()

    createDate = db.DateTimeProperty(auto_now_add=True)

class SearchResult(db.Model):
    title = db.StringProperty()
    content = db.StringProperty()

    who = db.StringProperty()
    what = db.StringProperty()
    where = db.StringProperty()

    createDate = db.DateTimeProperty(auto_now_add=True)

I'm duplicating a bunch of properties between the models for the sake of denormalization since I can't join Search and SearchResult together. Does this make sense? Or should I store a search ID in the SearchResult model and effectively "join" the two models in code when I retrieve them from the datastore? Please keep in mind that this is a simple example. Both models will have a lot more properties and the way I'm approaching this right now, I would put any property I put in the Search model in the SearchResult model as well.


回答1:


Don't duplicate the properties if they'll always be the same between the SearchResult and a Search. If a SearchResult should have a reference to a Search, keep a ReferenceProperty pointing to the Search. This basically stores the related Search's Key in the model.

class SearchResult(db.Model):
    search = db.ReferenceProperty(Search, required=True)
    # other stuff...

I also highly recommend you watch some of the App Engine videos from last year's Google I/O (and from 2008), in particular this one by Brett Slatkin, and this one by Ryan Barrett. They're all pretty helpful videos if you have the time, but I found those two in particular to be really great.



来源:https://stackoverflow.com/questions/2653074/schema-less-design-guidelines-for-google-app-engine-datastore-and-other-nosql-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!