Skip to content

MongoDB Database

Albin edited this page Feb 18, 2022 · 13 revisions

Pyshare MongoDB Database

Workload

Query Operation Description
Create user sign up Write Create a new user
Verify user on login Read Get user data and verify it against inserted data
Load user profile Read Get user data and contextualise it to profile
Modify user profile Write User can edit its user profile
Load post view Read Give the 10 latest posted problems
Iterate through post view Read Going through page by page where 10 post provided
Search on Posts Read Search through post on titles, tags, username
Write new Post Write User to write new post problem
open post and see problem Read Select a problem through user post view and see the problem
Submitted solution to post Write Add new submitted solution to post problem
Write Comment to Post Write Let user write comment to a post problem
Query Quantification Qualification
Create user sign up Require data genration Critical write
Verify user on login TO be giving some Priority with precise read
Load user profile statistics. Priority to be accurate
Modify user porfile not a priority write
Load post view Speed to read
Iterate through post view
Search on Posts
Write new Post
open post and see problem
Submitted solution to post
Comment to Post
Write Comment to Post Write
Remove posts solution with bad ranking
<-- This tables is not finished -->

Schema

Collections

  • Collection: users
"user": {
	"_id": 1,
	"schema": 2,
	"username": "<name>",
	"email": "<name>@<domain-name>.<domain-extension>",
	"password": "<password_hash argon2>",
	"role": "<level-name(admin, normie)>",
	"badges": ["<set of badges(pythonist, god, ...)>", "..." ],
	"posts": [ "<post_id>", "<post_id>", "..." ]
	"votes": { "<post_id>": 1, "<post_id>": -1, "..." }
	"solution_code": [
			{ "post_id": "<post_id>", "solution_id": "<solution_id>" }, 
			{ "post_id": "<post_id>", "solution_id": "<solution_id>" }, 
			"..." ],
	"created": "<Date>",
	"last_active": "<Date>"

}
  • Collection: posts
"post": {
	"_id": "<id>",
	"schema": 2,
	"title": "<post-title>",
	"title_hash": "<str(post-title_hash)>"
	"username": "<name>",
	"created": "<Date>",
	"description": "<text>",
	"rating": "<rating-score>",
	"solved": "<Boolean>",
	"test_code": "py code ... ",
	"solution_codes": [
			{
				"solution_id": "<post_id>+<solution_id>",
				"username": "<name>",
				"submitted": "<Date>",
				"ranking": "<ranking{Set of Best practice, clever, ..., braindead}>",
				"solution_code": "py code ..."
			},
			{
				"solution_id": "<post_id>+<solution_id>",
				"username": "<name>",
				"submitted": "<Date>",
				"ranking": "<ranking{Set of Best practice, clever, ..., braindead}>",
				"solution_code": "py code ..."
			},
		        "..."
			{
				"solution_id": "<post_id>+<solution_id>",
				"username": "<name>",
				"submitted": "<Date>",
				"ranking": "<ranking{Set of Best practice, clever, ..., braindead}>",
				"solution_code": "py code ..."
			}
	],
	"comments": [
		{
				"username": "<name>",
				"comment": "<text>",
				"submitted": "<Date>"
		},
		"..."
		{
				"username": "<name>",
				"comment": "<text>",
				"submitted": "<Date>"
		}
	]
}
  • Collection: tags
"post": {
	"_id": "<id>",
	"schema": 2,
	"title": "<title-name>"
}

Index

Index in Collections:

  • Users:

    • unique usernames
    • unique email
  • Posts:

    • unique titles
    • title_hash ascending order
    • $text titles
    • descending sort on field created
    • rating: descending
  • Tags:

    • unique tags name

Reasoning

The uniqueness of usernames is to prevent two users with the same name. The reasoning is that all users will be identified through the website and more importantly.

The uniqueness of email will prevent a new person to create a new account on the same email. This is a design decision due to allow a user to also be identified by email when logging in or having to forgotten username or password.

Posts will have unique titles to give searching and not giving two posts be seen as the same when looking at posts through post overview page and it gives ease of use for a user to searching for specific post.

The index for title hash is to give a efficient read and write time specially for the sort aggregation on the query.

The $text performs a text search on the content of the fields indexed with a text index. This is then clearly to allow searching on titles.

Descending sort on field created is a index where the latest created(date) is on top of the index and the oldest at the bottom. This index will server multiple reason as giving the functionality of deleting to old post or sort by latest.

The rating index on post is for likewise reasons on title_hash, efficiency on query and write.

Tags are unique due to not having tag with the same name.

Pattern

  • schema version control As the project develop and data generations gets going multiple newer schema of a Document. The schema version is a easy to not to perform schema validation. Instead now Documents will be check by schema number in the backed part of the program.

Clone this wiki locally