R
R
retyui2015-04-10 21:09:41
MongoDB
retyui, 2015-04-10 21:09:41

Data modeling in Mongodb?

Help me decide when creating a data model!
There are Groups of Students and N Tests.
Here is the first model when displaying the log of test results
, we also need to pull the necessary information from 2 collections (group and tests).

group{
groups:{
  users:{
    user1{a,b,c,...}
    user2{a,b,c,...}
    ....
  }
}

tests{
  name,
  questions:{
    question1{a,b,c,...}
    question2{a,b,c,...}
    ...
  }
}

logs{
  user.id,
  test.id,
  date,
  result
}

==========
2 structure
When using nesting, we can immediately write the necessary information to the result log. BUT if any user or test data changes, all affected documents will need to be updated.
groups:{
  users:{
    user1{a,b,c,...}
    user2{a,b,c,...}
    ....
  }
}

tests{
  name,
  questions:{
    question1{a,b,c,...}
    question2{a,b,c,...}
    ...
  }
}

logs{
  user{
    Name,
    Yaer,
    ...
  },
  test{
    Name,
    ...
  }
  date,
  result
}

Is there any optimal solution? Or offer your model.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2015-04-10
@sim3x

BUT if any user or test data changes, all affected documents will need to be updated.
now you understand the beauty of schemaless.
Assume how much you will write and read, and balance between
Easier to read VS easier to write

O
OnYourLips, 2015-04-11
@OnYourLips

BUT if any user or test data changes, all affected documents will need to be updated.
Because you are using a NoSQL database for relational data.
An error in the wrong choice of a DBMS for a specific task.

L
lega, 2015-04-11
@lega

There is little information on how you will then use the data.
As an option: users in a separate collection with a link to a group (or a list of groups)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question