node.js - Migrating from SQL Server DB to MongoDB: questions about whether to embed or to reference -


I am working on my first non-SCL design and I need some help so that the standard Ho.

I had a simple relational database:

  User (id, username, password, email, name, facebook id, dated) Question (id, user id, Question, dated) Answer (id, question, answer, date dated)  

I want to convert it to the Mongos schema. I'm not sure how much I have to embed and how much references I have to give. Here are some of my thoughts:

There is only one collection user, and embed everything in it:

  mongoose.model ('user', {userName: string , Password: string, e-mail: string, name: string, facebook id: string date credit: date question: [{question: string, date: date, answer: [{answer: string, given user: {type: Schema.Type object ID, ref: 'user'}}}}}}}  

There are two collections (max 10 I can limit the maximum number of numbers)

  mongoose.model ('user', {userName: string, password: string, email: string, name: string, facebookId: string date Credit: Date}); Mongoose.model ('Question', (Question: String, Date displayed: Date, Asked, User ID: {Type: Schema Type, Object ID, Ref: 'User'}, Answer: [[Answer : String, date: date, answered user: {type: schema type. There are 3 different collections (# of answers no limit):  
  Mongoose.model ('user', {userName: string, password: string, e-mail: string, name: string, facebook id: string date credit: date}); Mongoose.model ('Question', {Question: String; Date: Date, Asked IDIID: {Type: Schema Type, Object ID, Ref: 'User'}})}); Mongoose.model ('Answer', (Answer: String, Date displayed: Date, Answered UserID: {Type: schema type} Object ID, Ref: 'User'} Question id: {Type: Schema Type Object ID , Ref: 'question'}})});  

These are the types of inquiries:

  • GetAllUsers
  • GetAllQuestions
  • GetAllQuestionsWithAnswers
  • < GetAllQuestionsAskedByUser (userId)
  • GetAllAnswersAnweredByUser (userId)

Considering the previous two questions, is there a sense of reference in the context of users for fast access? collection?

mongoose.model ('user', {userName: string, password: string, e-mail: string, Name: String, Facebook Id: String, Date Credit: Date, Question: [{Type: Schema Type: Object ID, Ref: 'Question'}], Answer: [[Schema type.Object ID, Ref: 'Answer' }]});

Am I thinking in the right direction? In my scenario, which schema would be the best option?

I like the way of your thinking and analysis, applying for the problem.
The thing to consider is that records on the disc are kept after one to the other. If you are storing everything in a collection, and can develop question and answer arrays, then once there is no space between adding a question / answer, the record must be transferred - disk file fragmentation Due to the record of development you can allocate padding in advance, but a waste of disk space so that the approach is out I am thinking that the second thing is that, all It is more likely that you will not display any unanswered questions - or you might display a list of questions of the top 2-3 answers for each question - so that like a hybrid approach where the questionnaire is stored in an array The answers to each question will be 3 - There is no fragmentation, and the remaining answers are in a separate collection. Alternatively, you have mentioned that you have answered the answer to 10 You can limit all 10 "dummy" answers in advance and avoid fission (at the expense of disk space) in summary, I will go with a user collection, collection of a Quest where every question The record has a user pointing to it, who has asked it, and either a hybrid question / answer approach with a separate answer collection, or a question / answer Live where North array is limited to 10.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

c# - Chart control: Design messed Up after clearing and re-adding Y-Values -

ruby on rails - Apipie interferes with proper error codes -