【问题标题】:Cassandra/NoSQL newbie: the right way to model?Cassandra/NoSQL 新手:正确的建模方式?
【发布时间】:2023-03-30 03:03:01
【问题描述】:

正如标题所说,我对 NoSQL DBS(如 Cassandra)相当(阅读:完全)新手。和其他许多人一样,我之前学过 RMDBS。所以我读了一些关于“WTF 是一个超级专栏”和其他明显的谷歌热门文章,但我仍然不确定如何建模:

假设我想保存用户,如用户名/密码/姓名/等...如果该用户喜欢手机和固定电话怎么办?这是“正确”的做法吗? (使用与其他网站相同的缩写 JSON 样式)

Users: {    // <-- this is the Users SuperColumnFamily, keyed by username
    myuser: {    // <-- this is a User SuperColumn
        username = "myuser",    // <-- this is the username Column
        email = "myuser@googlemail.com",
        ...
    },
    ...
}

Phone: {    // <-- this is where the users phone numbers are stored
    myuser: {
        mobile = "0129386835235",
        landline = "123876912384",
    },
    ...
}

请指正/指正

【问题讨论】:

    标签: nosql cassandra


    【解决方案1】:

    首先,不要使用超级列。见:

    http://www.quora.com/Cassandra-database/Why-is-it-bad-to-use-supercolumns-in-Cassandra

    现在回答你的问题。您描述的示例很容易使用常规列族进行建模:

    Users: { <- This is the name of the column family
      username1: { <- this is a row key within the column family, it is one of your usernames
        email: user@email.com <- these are all of the columns within this row, they correspond to attributes for this user
        mobile: ...
        landline: ...
      }
      username2: { <- another row for a different user
        email: diff@email.com
      }
    }
    

    您可以在上面看到灵活的架构,因为每一行都有一组不同的列来描述该用户。

    有关 cassandra 数据模型的更多信息,我建议阅读 http://www.datastax.com/docs/1.0/ddl/index

    【讨论】: