【发布时间】:2019-07-21 22:26:02
【问题描述】:
因此,过去 3 年我一直在使用关系数据库,但我在创建 noSql 数据库的心态方面遇到了一些麻烦。我有以下型号:
class Account(ndb.Model):
first_name = ndb.StringProperty()
last_name = ndb.StringProperty()
email = ndb.StringProperty()
password = ndb.StringProperty()
class Organisation(ndb.Model):
org_name = ndb.StringProperty()
org_address = ndb.StringProperty()
.. and so on
class UserProfile(ndb.Model):
user = ndb.KeyProperty(kind='Account')
organisation = ndb.KeyProperty(kind='Organisation')
role = ndb.StringProperty()
帐户 x 组织在技术上是多对多关系,因此 UserProfile 就像一个链接表,就像在关系数据库中一样
据我了解,我不必执行超过 1 次查询即可获取有关实体的信息。例如,如果我查询以获取属于该用户的所有 UserProfiles,那么我不应该遍历并查询每个 UserProfiles 实体来单独获取有关每个组织的信息。我觉得我构建它的方式不是最好的或应该的方式。
我想到的另一件事是将组织详细信息存储在 Account 模型本身中,但是如果组织详细信息发生更改,那么我将不得不查询连接到该组织的所有帐户并单独更新每个帐户。
只是对如何做到这一点普遍感到困惑,任何关于我哪里出错的帮助或解释将不胜感激。
【问题讨论】:
-
Google 会将每个数据存储用户迁移到 NoSQL Cloud Firestore(在数据存储模式下)。但您也可以使用原生 Cloud Firestore,它有很多好处。更多:cloud.google.com/datastore/docs/upgrade-to-firestore
标签: python-2.7 google-app-engine data-structures nosql google-cloud-datastore