2

I'm building a simple blog system for multiple users, they can access data by userID, username and nodeID(blog).

In RDBMS, normally we will have user/table/ownership tables. In mongoDB, some suggest to put them in a single users collection. However, as far as i know, it could be very slow if users want to access specific nodeID, since mongoDB may go through every document. Indexing will significantly drop the create speed, in my case, that means both createUser() and createNode(), right?

Therefore, is there any "Best Practices" we can follow? Thanks.

SiddAjmera
  • 38,129
  • 5
  • 72
  • 110
zhuchun
  • 193
  • 4
  • 13
  • 1
    *"Indexing will significantly drop the create speed"* – how often are you inserting new data that this is a concern? "Significantly" still just means a few milliseconds most likely. – deceze Mar 02 '16 at 09:40
  • 1
    Possible duplicate of [mongodb schema design for blogs](http://stackoverflow.com/questions/5224811/mongodb-schema-design-for-blogs) – deceze Mar 02 '16 at 09:40
  • There are a few posts that you can refer for that. Here I'm listing a few : http://stackoverflow.com/questions/5224811/mongodb-schema-design-for-blogs https://www.mongodb.com/presentations/mongodb-melbourne-2012/schema-design-example https://docs.mongodb.org/ecosystem/use-cases/storing-comments/ http://blog.mongodb.org/post/87200945828/6-rules-of-thumb-for-mongodb-schema-design-part-1 – SiddAjmera Mar 02 '16 at 09:42
  • @deceze: few milliseconds at worst :) – Sergio Tulentsev Mar 02 '16 at 09:48
  • checkout this course that has a POC creating a mongodb for blog https://university.mongodb.com/courses/M101JS/about – medhatdawoud Mar 02 '16 at 11:35
  • Great! I'm going to read them 1 by 1. In fact I didn't find much official performance benchmark, therefore tutorials are the main sources. Some says _"If you use `ensureIndex()` for a field, you have half performance due to its mechanism, so just use `_id` to `find`"_. Well I have to say that's really confusing. Perhaps people exaggerate that performance issue. – zhuchun Mar 03 '16 at 10:49

1 Answers1

4

Three Collections Inside the DB, Namely,

"Users", 
"UserPosts", 
"UserComments"

Users Collection's Field could be

"name",
"age",
"occupation",
"profileImage",
"numberOfPosts", 
"birthdate", 
"joiningDate", 
"session"

etc.

UserPosts Collection's Field could be

    "Id", 
    "revisionId",
    "author",
    "type",
    "language",
    "userId",
    "status",
    "title",
    "tags",
    "content"

etc.

UserComments Collection's Field could be

    "Id", 
    "userPostId",
    "author",
    "type",
    "language",
    "userId",
    "status",
    "comment",

etc.

User Comment will be maintained by UserPostId Field It contains.

Nidhin David
  • 2,426
  • 3
  • 31
  • 45
Istiak Morsalin
  • 10,621
  • 9
  • 33
  • 65
  • Thanks! That looks exactly what we did in RDBMS, isn't it? Do you think it's necessary to use `db.UserPosts.ensureIndex({author:1})` and `db.UserComments.ensureIndex({author:1, userPostId:1})` for better performance(or just worse)? – zhuchun Mar 03 '16 at 10:55
  • No You did not need to do that. – Istiak Morsalin Mar 03 '16 at 12:05