# Add a Comment

Creating another Topic with another request

POST /api/createComment HTTP/1.1
Content-Type: application/json

{
  "body":"A 1st Comment on Topic #1",
  "topicId":"5dde6aab5aad123cee5da6c7",
  "parentId":"5dde6aab5aad123cee5da6c7"
}
1
2
3
4
5
6
7
8

Beside of the comment.body we also provided a topicId to link that comment to it's "root" Topic and a parentId wich will directly point to it's parent. A parent might be the root topic or another comment in case of a "reply".

# Events collection

Comment.created got added to events:

[...] // older events above
{
    "_id" : ObjectId("5dde77775aad123cee5da6cc"),
    "aggregateId" : ObjectId("5dde77775aad123cee5da6cb"),
    "aggregateVersion" : NumberInt(0),
    "type" : "Comment.created",
    "payload" : {
        "body" : "A 1st Comment on Topic #1",
        "topicId" : "5dde6aab5aad123cee5da6c7",
        "parentId" : "5dde6aab5aad123cee5da6c7",
        "countReplies" : NumberInt(0)
    },
    "context" : {
        "reqId" : "424f2987-2281-4779-9a18-7b8bd5eaf9d4"
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# Topics collection

1st Topic got an incremented counter countComments:




 







{
    "_id" : ObjectId("5dde6aab5aad123cee5da6c7"),
    "title" : "This is a 1st Topic",
    "countComments" : NumberInt(1)
}
{
    "_id" : ObjectId("5dde75915aad123cee5da6c9"),
    "title" : "This is a 2nd Topic",
    "countComments" : NumberInt(0)
}
1
2
3
4
5
6
7
8
9
10

# Threads collection

1st Thread got an incremented counter countComments and the comment got pushed to children:




 
 
 
 
 
 
 
 










{
    "_id" : ObjectId("5dde6aab5aad123cee5da6c7"),
    "title" : "This is a 1st Topic",
    "countComments" : NumberInt(1),
    "children" : [
        {
            "_id" : ObjectId("5dde77775aad123cee5da6cb"),
            "body" : "A 1st Comment on Topic #1",
            "countReplies" : NumberInt(0)
        }
    ]
}
{
    "_id" : ObjectId("5dde75915aad123cee5da6c9"),
    "title" : "This is a 2nd Topic",
    "countComments" : NumberInt(0),
    "children" : [

    ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# Comments collection

{
    "_id" : ObjectId("5dde77775aad123cee5da6cb"),
    "body" : "A 1st Comment on Topic #1",
    "topicId" : "5dde6aab5aad123cee5da6c7",
    "parentId" : "5dde6aab5aad123cee5da6c7",
    "countReplies" : NumberInt(0)
}
1
2
3
4
5
6
7
Last Updated: 11/27/2019, 3:58:28 PM