【问题标题】:Cassandra structure for comments and comment replies tables评论和评论回复表的 Cassandra 结构
【发布时间】:2019-08-07 22:42:52
【问题描述】:

我正在尝试创建一个网站,用户可以在其中撰写文字帖子,其他用户可以评论帖子,甚至其他用户可以回复评论。 Cassandra 新手,请帮助为此创建数据模型。

现有数据模型如下

CREATE TABLE users (
    user_id uuid,
    first_name text,
    last_name text,
    email text,
    created_date timestamp,
    PRIMARY KEY (userid)
);

CREATE TABLE user_credentials (
    email text,
    password text,
    userid uuid,
    PRIMARY KEY (email)
);


CREATE TABLE user_posts (
  user_id uuid,
  post_id timeuuid, 
  content text,
  PRIMARY KEY (user_id, post_id) )
WITH CLUSTERING ORDER BY (post_id DESC);


Create TABLE comment_by_post (
  post_id timeuuid,
  user_id uuid,
  comment_date timestamp, 
  context text ,
  primary key (post_id,user_id,comment_date))
WITH CLUSTERING ORDER BY (comment_date);


Create Table comment_by_user (
  post_id timeuuid ,
  user_id uuid,
  comment_date timestamp ,
  content text,
  primary key (user_id,post_id,comment_date))
WITH CLUSTERING ORDER BY (comment_date);

【问题讨论】:

  • 我认为这不是 cassandra 建模或 mysql 等的问题。首先您必须考虑您的应用程序中的用户是什么,您的应用程序中的帖子或评论是什么?
  • 它是一个简单的应用程序,用户可以在其中写帖子“文本”,其他用户可以评论帖子。@Novy
  • 您实际上并不需要用户凭据表,此信息可以存储在用户中。然后使用 spring 数据,您可以使用投影来仅显示用户存储库的某些部分。你的数据模型有什么问题? @shubham bhindwal
  • 我在创建评论系统时遇到问题,用户可以通过帖子@Novy 回复其他 cmets

标签: java database spring-boot cassandra


【解决方案1】:

我是 mongodb 开发人员,不是 cassandraDB 开发人员,但我可以帮助您处理一些数据模型,我将按照 json 语法进行建模:{attr: value}

评论/回复有两种方式:

  1. 在评论集合(cassandra 中的表格)中嵌入回复,如下所示:

    {
    
    
        commentID : 1,
        userID : 12,
        postID : 15,
        text : "some comment",
        /*other fields*/
        replies : [
    
            {
                replyID : 1,
                userID : 16,
                text : "some reply"
            },
            {
                replyID : 2,
                userID : 35,
                text : "some reply"
            },
        ]
     }
    
  2. 为每个 cmets 回复创建单独的集合(表):

cmets:

{
    commentID : 1,
    userID : 12,
    postID : 15,
    text : "some comment",
    /*other fields*/
}

回复:

{
    replyID : 1,
    replyTo : 1,
    userID : 16,
    text : "some reply"
}

{
    replyID : 2,
    replyTo : 1,
    userID : 35,
    text : "some reply"
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多