mosquito87
mosquito87

Reputation: 4440

Forum like data structure: NoSQL appropriate?

I'm trying to save data which has a "forum like" structure:

This is the simplified data model:

+---------------+
|     Forum     |
|               |
| Name          |
| Category      |
| URL           |
|               |
+---------------+
        |1
        |n
+---------------+
|               |
|     Thread    |
|               |
| ID            |
| Name          |
| Author        |
| Creation Date |
| URL           |
|               |
+---------------+
        |1
        |n
+---------------+
|               |
|      Post     |
|               |
| Creation Date |
| Links         |
| Images        |
|               |
+---------------+

I have multiple forums/boards. They can have some threads. A thread can contain n posts (I'm just interested in the links, images and creation date a thread contains for data analysis purposes).

I'm looking for the right technology for saving and reading data in a structure like this.

While I was using SQL databases heavily in the past, I also had some NoSQL projects (primarily document based with MongoDB). I'm sure MongoDB is excellent for STORING data in such a structure (Forum is a document, while the Threads are subdocuments. Posts are subdocuments in Threads). But what about reading them? I have the following use cases:

Which technology is best for those use cases?

Upvotes: 3

Views: 1990

Answers (1)

notionquest
notionquest

Reputation: 39226

Please find below my draft solution. I have considered MongoDB for the below design.

Post Collection:-

"image" should be stored separately in GridFS as MongoDB collection have a maximum size of 16MB. You can store the ObjectId of the image in the Post collection.

{
    "_id" : ObjectId("57b6f7d78f19ac1e1fcec7b5"),
    "createdate" : ISODate("2013-03-16T02:50:27.877Z"),
    "links" : "google.com",
    "image" : ObjectId("5143ddf3bcf1bf4ab37d9c6e"),
    "thread" : [ 
        {
            "id" : ObjectId("5143ddf3bcf1bf4ab37d9c6e"),
            "name" : "Sam",
            "author" : "Sam",
            "createdate" : ISODate("2013-03-16T02:50:27.877Z"),
            "url" : "https://www.wikipedia.org/"
        }
    ],
    "forum" : [ 
        {
            "name" : "Andy",
            "category" : "technology",
            "url" : "https://www.infoq.com/"
        }
    ]
}

In order to access the data by category, you can create an index on "forum.category" field.

db.post.createIndex( { "forum.category": 1 } )

In order to access the data by links, you can create an index on "links" field.

db.organizer.createIndex( { "links": 1 } )

Please note that the indexes are not mandatory. You can access/query the data without index as well. You can create indexes if you need better read performance.

I have seen applications using MongoDB for similar use case as yours. You can go ahead with MongoDB for the above mentioned use cases (or access patterns).

Upvotes: 2

Related Questions